[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

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

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
  • 2
1 Solution
You don't.

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

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)

lybreezeAuthor Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now