Connect a VB.Net 2010 website to a Crystal Reports .NET Framework 4.0 report
Posted on 2011-10-05
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
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.]
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