Skip to Content
0
Jun 02, 2020 at 06:38 PM

How to pass Database logon info to a Crystal Report at runtime in or in C#.net

846 Views Last edit Jun 02, 2020 at 06:42 PM 2 rev

I'm trying to upgrade from CR for Visual Studio 2013 CR Version=13.0.2000.0 to Version=13.0.4000.0. In the prior version I used the following code :

VB.Net

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

PartialClassCalendarRaffle_CalendarMailingLabels

Inherits System.Web.UI.Page

ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load

Dim report AsNew ReportDocument()

report.Load(Server.MapPath("CalendarWinerMailInfo.rpt"))

SetTableLocation(report.Database.Tables)

CrystalReportViewer1.ReportSource = report

EndSub

PrivateSub SetTableLocation(ByVal tables As Tables)

Dim connectionInfo AsNew ConnectionInfo()

connectionInfo.ServerName = "My Server"

connectionInfo.DatabaseName = "my database"

connectionInfo.UserID = "my usernm"

connectionInfo.Password = "my password"

ForEach table As CrystalDecisions.CrystalReports.Engine.Table In tables

Dim tableLogOnInfo As TableLogOnInfo = table.LogOnInfo

tableLogOnInfo.ConnectionInfo = connectionInfo

table.ApplyLogOnInfo(tableLogOnInfo)

Next

EndSub

EndClass

It worked perfectly.

However, when I tried converting it to C# and used it with the current Version=13.0.4000.0:

C#

using System;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

internalpartialclassHQadmin_CalendarMailingLabels : System.Web.UI.Page

{

public HQadmin_CalendarMailingLabels()

{

this.Load += Page_Load;

}

protectedvoid Page_Load(object sender, EventArgs e)

{

var report = newReportDocument();

report.Load(Server.MapPath("CalendarWinerMailInfo.rpt"));

SetTableLocation(report.Database.Tables);

CrystalReportViewer1.ReportSource = report;

}

privatevoid SetTableLocation(Tables tables)

{

var connectionInfo = newConnectionInfo();

connectionInfo.ServerName = "my server";

connectionInfo.DatabaseName = "my database";

connectionInfo.UserID = "usernm";

connectionInfo.Password = "password";

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)

{

TableLogOnInfo tableLogOnInfo = table.LogOnInfo;

tableLogOnInfo.ConnectionInfo = connectionInfo;

table.ApplyLogOnInfo(tableLogOnInfo);

}

}

}

It doesn't work. I am unable to find any examples of how to do this with the current version. Can someone please tell me what I have to do to get this to work!!!!! Also if there is documentation and code examples for this current version, please let me know where to find it.