Connect a VB.Net 2010 website to a Crystal Reports .NET Framework 4.0 report

Posted on 2011-10-05
Last Modified: 2012-05-12
I've spent far too long trying to get this to work, and I need some help please.

I've developed a VB Net 2010 website that contains a Crystal Reports report, connecting to a remote SQL Server database, but I can't figure out how to pass the SQL Server connection details to Crystal Reports.

I followed a tip to create a Protected Sub that handles the login - see below, but I can't see how to pass the name of my .rpt as a parameter, i.e.  poreport

Protected Sub LogOn(ByVal poReport As CrystalDecisions.CrystalReports.Engine.ReportDocument)

        Dim lsMethod As String = System.Reflection.MethodBase.GetCurrentMethod().Name
        Dim loConnInfo As New CrystalDecisions.Shared.ConnectionInfo
        Dim lsMode As String = ConfigurationManager.AppSettings("Mode")

        loConnInfo.ServerName = "111.222.333.444"
        loConnInfo.DatabaseName = "mydb"
        loConnInfo.UserID = "myusername"
        loConnInfo.Password = "mypassword"

        Dim loTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim loTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim loTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

        loTables = poReport.Database.Tables
        For Each loTable In loTables
            loTableLogonInfo = loTable.LogOnInfo
            loTableLogonInfo.ConnectionInfo = loConnInfo
    End Sub

The error that I am getting when I run it locally is "Invalid report file path", and the error message when I run it on the web host is :-
[SecurityException: That assembly does not allow partially trusted callers.]
   CrystalDecisions.CrystalReports.Engine.ReportDocument..cctor() +0

I think I need to call the LogOn sub from CrystalReportViewer1_Init, but how do I supply the name of my report, e.g.  "myreport.rpt"

Very grateful for any help
Question by:lybreeze
    LVL 100

    Expert Comment

    You don't.

    You are passing a report document into the subroutine.  It should already be associated with your report file.

    LVL 100

    Accepted Solution

    Code will be something like

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
            ' Load the selected report file.
            Dim CR As New ReportDocument
            CR.Load("C:\Import Print\ImportPrint\bin\Templates\Bard\TestReport.rpt")
             Logon (CR)


    Author Closing Comment

    Thanks mlmcc

    It was the .Load that I was missing.

    The Crystal Reports report is now loading ok when run locally, although I am getting an error message when I try and run it remotely on Fasthosts -

    [SecurityException: That assembly does not allow partially trusted callers.]
       CrystalDecisions.CrystalReports.Engine.ReportDocument..cctor() +0

    However, that is a different problem (unless you happen to know the answer) so I will close this question now.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now