Results 1 to 28 of 28

Thread: [RESOLVED] Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Resolved [RESOLVED] Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    I am having a heck of a time trying to load a Crystal Report from my app. This is my first time using a Crystal Report. I have created the
    report using a project data ADO.Net DataSet.

    I have a button on a report menu which should load the report in a Crystal Report viewer on another form. I have tried this code every which
    way and I can't get the report to load. On my dev machine I use Integrated Login to SQL with local reports. The customer does not have a
    server just peer to peer network. The reports are all copied onto their machine in the same directory I have them in on mine.

    The code for the button...
    Code:
       Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
            Try
                Using connection As New SqlConnection(My.Settings.EAConnectionString)
                    ' Create the command and set its properties.
                    Dim command As SqlCommand = New SqlCommand()
                    command.Connection = connection
                    command.CommandText = "worldirReport"
                    command.CommandType = CommandType.StoredProcedure
    
                    ' Open the connection and execute the reader.
                    connection.Open()
                    Dim reader As SqlDataReader = command.ExecuteReader()
                    connection.Close()
                End Using
            Catch ex As Exception
                MessageBox.Show("Error while getting world directory data..." & ex.Message, "Error Getting Records")
            Finally
    
            End Try
            Dim cryRpt As New ReportDocument
            Dim crtableLogoninfos As New TableLogOnInfos
            Dim crtableLogoninfo As New TableLogOnInfo
            Dim crConnectionInfo As New ConnectionInfo
            Dim CrTables As Tables
            Dim CrTable As Table
    
            cryRpt.Load("C:\Member Program\Member Program\Member Program\Reports\worldir.rpt")
    
            With crConnectionInfo
                .ServerName = "MT1-MARY"
                .DatabaseName = "MT"
                .UserID = "Mary"
                .Password = "12345"
            End With
    
            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next
    
            CrystalReportViewer.CrystalReportViewer1.ReportSource = cryRpt
            CrystalReportViewer.CrystalReportViewer1.Refresh()
        End Sub
    The login credentials for SQL are correct because the program is loading and saving data from the winforms app, which uses those same
    credentials.

    I get this error...
    Code:
    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException: Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack.
       at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
       at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
       at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
       --- End of inner exception stack trace ---
       at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
       at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
       at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
       at Member_Program.ReportMenuForm.Button3_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    
    
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.269 (RTMGDR.030319-2600)
        CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    Member Program
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///C:/Users/Mary/AppData/Local/Apps/2.0/VPRX1712.O3H/RWYMXDY0.BCV/memb..tion_5463e4b4b71f3cf8_0001.0000_7aa6315522134d65/Member%20Program.exe
    ----------------------------------------
    Microsoft.VisualBasic
        Assembly Version: 10.0.0.0
        Win32 Version: 10.0.30319.1 built by: RTMRel
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.269 built by: RTMGDR
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Core
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.233 built by: RTMGDR
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.269 built by: RTMGDR
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 built by: RTMRel
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Runtime.Remoting
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    System.Deployment
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Deployment/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
    ----------------------------------------
    System.Xml
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.233 built by: RTMGDR
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    CrystalDecisions.CrystalReports.Engine
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.CrystalReports.Engine/13.0.2000.0__692fbea5521e1304/CrystalDecisions.CrystalReports.Engine.dll
    ----------------------------------------
    System.Data
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.237 (RTMGDR.030319-2300)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
    ----------------------------------------
    CrystalDecisions.Windows.Forms
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.Windows.Forms/13.0.2000.0__692fbea5521e1304/CrystalDecisions.Windows.Forms.dll
    ----------------------------------------
    CrystalDecisions.Shared
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.Shared/13.0.2000.0__692fbea5521e1304/CrystalDecisions.Shared.dll
    ----------------------------------------
    System.Configuration
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Transactions
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
    ----------------------------------------
    System.EnterpriseServices
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    ----------------------------------------
    CrystalDecisions.ReportSource
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportSource/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportSource.dll
    ----------------------------------------
    System.Web
        Assembly Version: 4.0.0.0
        Win32 Version: 4.0.30319.272 built by: RTMGDR
        CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
    ----------------------------------------
    log4net
        Assembly Version: 1.2.10.0
        Win32 Version: 1.2.10.0
        CodeBase: file:///C:/Windows/assembly/GAC_32/log4net/1.2.10.0__692fbea5521e1304/log4net.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.CommLayer
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CommLayer/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CommLayer.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.ClientDoc
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ClientDoc/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ClientDoc.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.DataDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataDefModel.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.CubeDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.CubeDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CubeDefModel.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.ReportDefModel
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.ReportDefModel/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ReportDefModel.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.Controllers
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.Controllers/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.Controllers.dll
    ----------------------------------------
    CrystalDecisions.ReportAppServer.DataSetConversion
        Assembly Version: 13.0.2000.0
        Win32 Version: 13.0.2.469
        CodeBase: file:///C:/Windows/assembly/GAC_MSIL/CrystalDecisions.ReportAppServer.DataSetConversion/13.0.2000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataSetConversion.dll
    ----------------------------------------
    
    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.
    
    For example:
    
    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>
    
    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.
    My program is compiled for x86 and .NET Framework 4. I have the 32 bit Crystal Report Runtime loaded. When I try to run these reports on my computer
    I get the database login screen and I tried checking the integrated box but it just fails. I have been working on this for days and I'm about ready to loose
    it so any help you can provide would be so very much appreciated.

    Thanks,
    Stacy

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    What line is causing the error, this one
    Code:
    cryRpt.Load("C:\Member Program\Member Program\Member Program\Reports\worldir.rpt")
    You might try setting the reports Build Action property to Embedded resource, then the report becomes part on the apps exe and you don't have to copy it to all of the different workstations and you don't have to load the report. You would just,
    Code:
    Dim crRpt as New yourReportName
    If you designed it using an ADO .Net Dataset then you could load the data like this,
    Code:
                Dim frm As New frmReports
                Dim ds As New WaterTablesDataSet
                Dim ta As New WaterTablesDataSetTableAdapters.InvoicesHeaderTableAdapter
                ta.Fill(ds.InvoicesHeader)
                Dim rpt As New rptInvoiceListing
                rpt.SummaryInfo.ReportTitle = clsCoInfo.CompName
                rpt.SetDataSource(ds)
                frm.CrystalReportViewer1.ReportSource = rpt
                frm.Show()

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Thank you soooo much for your reply.

    Quote Originally Posted by wes4dbt View Post
    What line is causing the error, this one
    Code:
    cryRpt.Load("C:\Member Program\Member Program\Member Program\Reports\worldir.rpt")
    It doesn't show me which line is popping an error because it is delivered. That machine doesn't have full VS2010 loaded on it.

    You might try setting the reports Build Action property to Embedded resource, then the report becomes part on the apps exe and you don't have to copy it to all of the different workstations and you don't have to load the report. You would just,
    Code:
    Dim crRpt as New yourReportName
    All of the reports are Embedded Resource and Do Not copy in the Copy to Output Directory.

    If you designed it using an ADO .Net Dataset then you could load the data like this,
    Code:
                Dim frm As New frmReports
                Dim ds As New WaterTablesDataSet
                Dim ta As New WaterTablesDataSetTableAdapters.InvoicesHeaderTableAdapter
                ta.Fill(ds.InvoicesHeader)
                Dim rpt As New rptInvoiceListing
                rpt.SummaryInfo.ReportTitle = clsCoInfo.CompName
                rpt.SetDataSource(ds)
                frm.CrystalReportViewer1.ReportSource = rpt
                frm.Show()
    I will try loading like this.
    Thanks,
    Stacy

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    [QUOTE
    If you designed it using an ADO .Net Dataset then you could load the data like this,
    Code:
                Dim frm As New frmReports
                Dim ds As New WaterTablesDataSet
                Dim ta As New WaterTablesDataSetTableAdapters.InvoicesHeaderTableAdapter
                ta.Fill(ds.InvoicesHeader)
                Dim rpt As New rptInvoiceListing
                rpt.SummaryInfo.ReportTitle = clsCoInfo.CompName
                rpt.SetDataSource(ds)
                frm.CrystalReportViewer1.ReportSource = rpt
                frm.Show()
    [/QUOTE]

    Loaded the data as you suggested and now I get the following error:
    Code:
    Mixed mode assembly is built against version v2.0.50727 of the runtime and cannot be loaded in the 4.0 runtime without addition configuration information.
    What does that mean?

    Thanks,
    Stacy

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Did you design these reports in the current versions of VB and CR that you are using?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Quote Originally Posted by wes4dbt View Post
    Did you design these reports in the current versions of VB and CR that you are using?
    I designed them in VS2010 Professional and SAP Crystal Reports for Visual Studio 2010. The client machine only has .net 4.0 runtime (which I what I compile for) and CR Runtime x32 and x64.

    Do I need to put any database login info in that button to run the report?

    Thanks,
    Stacy

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    You said in your first post that the CR report didn't run on your machine. You should get the report working on your machine before trying to get it to work on your clients machine.
    When I try to run these reports on my computer
    I get the database login screen and I tried checking the integrated box but it just fails
    If your able to load the Dataset and then use that as the reports datasource, then CR doesn't even touch the database. This forum has the best CR experts that I've found http://scn.sap.com/welcome?original_...ms.sdn.sap.com

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Thanks so much wes4dbt. I did have it working on my machine but had a brain fart when I was building the reports and named my SQL server by name, which did not go over well when I tried to move it to another computer. Anyway I redid the report using a dataset so it would be available on any computer. It hasn't worked on my machine since.

    -Stacy

  9. #9
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Try something simple,

    1. Go to the Project Menu and select Add New Item
    2. Select Crystal Report
    3. When the next window opens up, Select "Using the Report wizard"
    4. In the data window Select Project Data->ADO Datasets, then select one of your datasets, then select a datatable. continue with the wizard till you finish.
    I just did those steps and then added this code in a Button click event and the report worked
    Code:
            Dim ds As New WaterTablesDataSet
            Dim ta As New WaterTablesDataSetTableAdapters.CropsTableAdapter
            ta.Fill(ds.Crops)
            Dim rpt As New CrystalReport5
            rpt.SetDataSource(ds)
            Dim frm As New frmReports
            frm.CrystalReportViewer1.ReportSource = rpt
            frm.Show()
    Adjust you code with the propery dataset and Datatable name for your report.

    If you can't get this to work post your code and explain what happens. Also, try posting your problem at the SAP forum

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Quote Originally Posted by wes4dbt View Post
    Try something simple,

    1. Go to the Project Menu and select Add New Item
    2. Select Crystal Report
    3. When the next window opens up, Select "Using the Report wizard"
    4. In the data window Select Project Data->ADO Datasets, then select one of your datasets, then select a datatable. continue with the wizard till you finish.
    I just did those steps and then added this code in a Button click event and the report worked
    Code:
            Dim ds As New WaterTablesDataSet
            Dim ta As New WaterTablesDataSetTableAdapters.CropsTableAdapter
            ta.Fill(ds.Crops)
            Dim rpt As New CrystalReport5
            rpt.SetDataSource(ds)
            Dim frm As New frmReports
            frm.CrystalReportViewer1.ReportSource = rpt
            frm.Show()
    Adjust you code with the propery dataset and Datatable name for your report.

    If you can't get this to work post your code and explain what happens. Also, try posting your problem at the SAP forum
    I tried your idea and made a new report. Ran it and this is the error I get.
    Code:
    Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
    I'm trying to get some data on this error now, but have you ever seen this before?
    Thanks,
    Stacy

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Ok Found some info on this error ...http://msmvps.com/blogs/rfennell/arc...eb-server.aspx

    But it didn't fix my problem.
    -Stacy

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    GOT IT WORKING!!!!! YEAH
    Ended up changing it to .NET 3.5. Recompiled got an error and had to do this...
    Open the Resources.resx file in a text editor, Notepad will do. Search for "4.0.0.0" and change that to "2.0.0.0". That might not fix the problem, some resources are binary serialized and embedded as a base64 encoded string in the .resx file. You'll easily recognize them as a long string. You'll need to fix those with the Visual Studio resource editor, remove them and add them back.

    Then I got another error so in my programs bin - debug directory I had to change the 4.0.0.0 to 2.0.0.0 in the ApplicationName.exe.config file.
    NOW it works! All I can say is what a pain in the butt. All because I wanted to use Crystal Reports.

    Thanks,
    Stacy

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    It will run even when compiled on my machine. Keep getting weird errors now though. It's like it doesn't keep the 2.0.0.0 in my applicationName.exe.config file. Also SVHost keeps crashing when I debug from in VS2010. Hummm...maybe I shouldn't have gone down to .NET 3.5. I couldn't get the fixes to work for the 4.0.0.0 though.

    I'll try the SAP forum and see what they have to say. If you have an clues please let me know though.
    Thanks,
    Stacy

  14. #14
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    check your App.config file and make sure you have these lines
    Code:
      <startup useLegacyV2RuntimeActivationPolicy="true">
        
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
    Are you sure your using CR for VB 2010? I had simular problem with CR reports that I developed in VB 2005 and then updated the app to VB 2010. Adding those lines to my App.config solved the problem.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Quote Originally Posted by wes4dbt View Post
    check your App.config file and make sure you have these lines
    Code:
      <startup useLegacyV2RuntimeActivationPolicy="true">
        
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
    Are you sure your using CR for VB 2010? I had simular problem with CR reports that I developed in VB 2005 and then updated the app to VB 2010. Adding those lines to my App.config solved the problem.
    This is what my appconfig looks like...
    Code:
    <?xml version="1.0"?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="Member_Program.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <connectionStrings>
            <add name="Member_Program.My.MySettings.EAConnectionString" connectionString="Data Source=STACY-LAPTOP\SQLEX;Initial Catalog=EA;User Id=*****;Password=*****;"
                providerName="System.Data.SqlClient" />
        </connectionStrings>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        </startup>
        <userSettings>
            <Member_Program.My.MySettings>
                <setting name="zmemid" serializeAs="String">
                    <value>0</value>
                </setting>
                <setting name="zgrpid" serializeAs="String">
                    <value>0</value>
                </setting>
            </Member_Program.My.MySettings>
        </userSettings>
    </configuration>
    It is missing that code you suggested. I will try that when I get back in the office. I have never had any other version of Visual Studio or Crystal Report loaded on any of these computers.

    I'll let you know.

    Thanks,
    Stacy

  16. #16
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Under Project-> Complie, select "advanced compile options", try setting Target x86 and .Net Framework 4. That's how my apps are set.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Quote Originally Posted by wes4dbt View Post
    Under Project-> Complie, select "advanced compile options", try setting Target x86 and .Net Framework 4. That's how my apps are set.
    Yep that is how it was set up until I tried recompiling using 3.5. I did keep a copy of the program before I recompiled so I can go back to that version and add that code in the app.config. Does it matter where I place that code in the config?

    Thanks so much for your help with this. I really appreciate it.
    Stacy

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    I've add that legecy code near the top of the app.config and now I'm getting this weird error.

    The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.

    Thanks,
    Stacy

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    I think I've got them running now. Here is what I ended up with for the App.config
    Code:
    <?xml version="1.0"?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="Member_Program.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <connectionStrings>
            <add name="Member_Program.My.MySettings.EAConnectionString" connectionString="Data Source=STACY-LAPTOP\SQLEX;Initial Catalog=EA;User Id=sa;Password=@c3comp;"
                providerName="System.Data.SqlClient" />
        </connectionStrings>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        </startup>
        <userSettings>
            <Member_Program.My.MySettings>
                <setting name="zmemid" serializeAs="String">
                    <value>0</value>
                </setting>
                <setting name="zgrpid" serializeAs="String">
                    <value>0</value>
                </setting>
            </Member_Program.My.MySettings>
        </userSettings>
    </configuration>
    I haven't tried compiling and putting on my client computer yet though so I can't be sure.

    Since I am changing the reports to use DataSets now instead of queries directly to the SQL Server. Can I still pass variables like I was?
    Code:
        Dim zcrystalviewer As New CrystalReportViewer
        zcrystalviewer.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel
        zcrystalviewer.CrystalReportViewer1.ShowGroupTreeButton = False
        zcrystalviewer.Show()
        Dim cryRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        cryRpt.Load("C:\Member Program\Member Program\Member Program\Reports\statelst.rpt")
        cryRpt.SetDatabaseLogon("sa", "3ASQL402", "EA1-MARY\SQLEX", "EA")
    
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue
    
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("State")
        crParameterValues = crParameterFieldDefinition.CurrentValues
    
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    
        zcrystalviewer.CrystalReportViewer1.ReportSource = cryRpt
        zcrystalviewer.CrystalReportViewer1.Refresh()
    I'm almost there I think.

    Thanks,
    Stacy

  20. #20
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Maybe try creating a new project with just one form a CR report viewer and a simple CR Report. Then add the code to your app.config. If it doesn't work you could post the file code and file.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    I've got the reports working now but I'm loading them how you suggested and I'm not sure how to pass variables doing it that way. Every example I find online shows loading the report the way I was and then they would show how to use variables.

    Do you pass variables to your Crystal Reports? How do you do it?

    Thanks,
    Stacy

  22. #22
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    You caught me in between posts. I'll look at your code.

    Since I am changing the reports to use DataSets now instead of queries directly to the SQL Server. Can I still pass variables like I was?
    thats the beauty of using datasets. You can query your db using any SQL statement you need. Just create a TableAdapter that fits your needs. You don't even need to use a TableAdapter, you can use dataadapter or fill the Datasets tables manually. Just as long as the datatables have the same name and schema

  23. #23
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    I never use CR Parameters, I use TableAdapter Parameters.

    Here's an example,
    Code:
            taU.FillByUserIdRange(ds.users, Me.UserStartComboBox.Text, Me.UserEndComboBox.Text)
            taO.Fill(ds.owners)
            If Me.ReportName = "GroupsByUserIdNoDoubles" Then
                taGrp.FillByNoDoubles(ds.groups)
                taL.FillByNoDoubles(ds.lots)
            ElseIf Me.ReportName = "GroupsByUserIdAll" Then
                taGrp.FillByAll(ds.groups)
                taL.FillAll(ds.lots)
            End If
    
            Dim rpt As New GroupsByUserId
            rpt.SummaryInfo.ReportTitle = "Groups Listing By water User Id"
            rpt.SummaryInfo.ReportAuthor = clsCoInfo.CompName
            rpt.SetDataSource(ds)
            frm.CrystalReportViewer1.ReportSource = rpt
            frm.ShowDialog()
    I fill the ds.users datatable with a start and ending "User" range
    I fill the ds.groups datatable with different sets of data depending on which report I'm running.
    This lets you use the same report for multiple purposes.

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Ok I was manually filling the datasets. I have this one report that needs to allow the user to select a State. With an RDLC I ususally prompt user for parameter then fill my dataset and then run the report.

    With this Crystal Report (State List) I also need to place that parameter on the report. So it will show at the top that they are running the report on State...whatever they selected. I had this working before I realized I screwed it up and built them wrong.

    This is what I have so far to run this report. I am kinda trying to do it like I do with an RDLC - prompt user for State then fill the dataset but I'm not sure this is the best way or how to pass the variable to Crystal Reports now.

    Should I just fill the dataset with all the records and let Crystal Reports prompt for the State and then filter?
    Code:
      Private Sub StateListButton_Click(sender As System.Object, e As System.EventArgs) Handles StateListButton.Click
            Dim zinput As New ReportInputDialog()
            zinput.ComboBox1.Visible = True
            zinput.Label1.Visible = True
            zinput.Label1.Text = "State:"
            zinput.ComboBox1.DataSource = zinput.StatesBindingSource
            zinput.StatesBindingSource.Sort = "Name ASC"
            zinput.ComboBox1.DisplayMember = "Name"
            zinput.ComboBox1.ValueMember = "Name"
            If zinput.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
    
                Dim SearchValue = zinput.ComboBox1.Text
                If String.IsNullOrEmpty(SearchValue) Then
                    MsgBox("You need to select a State to run this report.", MsgBoxStyle.OkOnly, "Oops!")
                Else
                    Dim ds As New StateListReportDataSet
                    Dim ta As New StateListReportDataSetTableAdapters.statelstTableAdapter
                    ta.FillByWorldDir(ds.statelst)
                    Dim rpt As New statelst
                    rpt.SetDataSource(ds)
    
                    'Dim crParameterFieldDefinitions As ParameterFieldDefinitions
                    'Dim crParameterFieldDefinition As ParameterFieldDefinition
                    'Dim crParameterValues As New ParameterValues
                    'Dim crParameterDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue
    
                    'crParameterDiscreteValue.Value = TextBox1.Text
                    'crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
                    'crParameterFieldDefinition = crParameterFieldDefinitions.Item("State")
                    'crParameterValues = crParameterFieldDefinition.CurrentValues
    
                    'crParameterValues.Clear()
                    'crParameterValues.Add(crParameterDiscreteValue)
                    'crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
                    Dim frm As New CrystalReportViewer
                    frm.CrystalReportViewer1.ReportSource = rpt
                    frm.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel
                    frm.Show()
                End If
            End If
            zinput.Dispose()
        End Sub
    Stacy

  25. #25
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    With this Crystal Report (State List) I also need to place that parameter on the report
    No you don't. The example I posted does exactly what your talking about with no CR parameters

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    YES! You're right. I was over complicating things, which I tend to do when I've been working on something for a week.

    I have it working on my machine. It puts that State at the top of the page. This should work.

    Thanks wes4dbt for all your help it is much appreciated. I added to your reputation

    Thanks,
    Stacy

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Jun 2012
    Location
    Minnesota
    Posts
    238

    Re: Desperately Need Help Loading A Crystal Report from Winforms App with SQL 2008 R2

    Well I compiled and installed on client machine and the Crystal Reports are working perfectly!

    Thanks Again! Problem Resolved.

    Stacy

  28. #28
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: [RESOLVED] Desperately Need Help Loading A Crystal Report from Winforms App with

    Glad I could help.

    CR can be a pain in the butt. It's a very powerful reporting tool once you learn how to work with it. VB doesn't really give you much choice but to use a third party reporting tool if you want to produce complex reports. It never made sense to me why they neglected reporting. Every app I've ever made produces reports.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width