• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • 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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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