cancel
Showing results for 
Search instead for 
Did you mean: 

CRVS2010 Beta --Can't change the logon information

Former Member
0 Kudos

when I use the following code to change the database logon information, after calling method ApplyLogOnInfo, the logon information in each table of ReportDocument can't be changed

void SetReportDBInfo(ref CrystalDecisions.CrystalReports.Engine.Tables a_tbls)

{

DbConnectionStringBuilder dbBuilder = DatabaseHelper.GetSqlConnectionStringBuilder();

SqlConnectionStringBuilder sqlBuilder = null;

if ((sqlBuilder = dbBuilder as SqlConnectionStringBuilder) != null)

{

foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in a_tbls)

{

CrystalDecisions.Shared.TableLogOnInfo logInfo = (TableLogOnInfo)tbl.LogOnInfo.Clone();

logInfo.ConnectionInfo.LogonProperties.Clear();

logInfo.ConnectionInfo.AllowCustomConnection = true;

logInfo.ConnectionInfo.ServerName = sqlBuilder.DataSource;

logInfo.ConnectionInfo.DatabaseName = sqlBuilder.InitialCatalog;

logInfo.ConnectionInfo.UserID = sqlBuilder.UserID;

logInfo.ConnectionInfo.Password = sqlBuilder.Password;

tbl.ApplyLogOnInfo(logInfo);

bool ret = tbl.TestConnectivity();

}

}

}

the result of method TestConnectivity is aslo false. please tell me why, thanks! By the way I use CRVS2010 Beta2 and VS2010 and I set up the reportsource of CrystalViewer in Page_Load, and the code is:

ReportDocument rd = new ReportDocument();

rd.Load(Server.MapPath(path));

CrystalDecisions.CrystalReports.Engine.Tables tbls = rd.Database.Tables;

SetReportDBInfo(ref tbls);

rd.Refresh();

SPRCrystalReportViewer.ReportSource = rd;

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Scott,

Here are the piece of code that works at my end. I would request you to please use the same and see if it helps.

private void btnViewer_Click(object sender, System.EventArgs e)
		{
			TableLogOnInfo boTableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();
			boTableLogOnInfo.ReportName =""; 
			boTableLogOnInfo.TableName = "Customers";
			boTableLogOnInfo.ConnectionInfo.ServerName="DBInUse";
			boTableLogOnInfo.ConnectionInfo.UserID="Uid";
			boTableLogOnInfo.ConnectionInfo.Password="Password";
			boTableLogOnInfo.ConnectionInfo.DatabaseName="Northwind";

			CrystalReportViewer1.LogOnInfo.Add(boTableLogOnInfo);
			CrystalReportViewer1.ReportSource = Server.MapPath("Day-5-Report.rpt");
}

CrystalReportViewer1 is the viewer control.

Thanks.

Former Member
0 Kudos

Hi, A G,

I already try the way what you said, and it actually can display the report correctly on my machine, but the data in the report is not correct, the old data source is still used by the report. By the way the report files are created by the old version of Crystal Reports, and I want to use these old report files in new Crystal Report Viewer, because we have replaced Access database with SQL Server ,so I must change the data source of these reports dynamically while displaying them. but it can't work.

Thanks!

Former Member
0 Kudos

Hello,

Are you changing the provider also? like from ODBC to OLEDB?

Look at these notes, it might be useful:

[1214777 - How to change the data source using CR for VS .NET application |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

[1217802 - How to change the database and server at runtime using the RAS .NET SDK |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

Thanks.

Former Member
0 Kudos

Hi A G,

I just want to change the data source of report from Access to SQL server 2005 dynamically, because we have already upgraded our database from Access to SQL Server 2005, but we don't want to change the report files, so we hope we can change the datasource of reports to SQL server by programming. Do you have any ways to do that?

Thanks!

Former Member
0 Kudos

Hello,

Does this [sample|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a0b05250-df37-2c10-2cba-a99b69e89ae8] help?

Thanks.

0 Kudos

Hi Scott,

You must use the ReplaceConnection method when updating the database driver. You'll also have to use RAS. Here's the code on how to...

ISCDReportClientDocument rptClientDoc;

private void ReplaceConnection_Click(object sender, EventArgs e)

{

ISCDReportClientDocument rcd;

rcd = rptClientDoc;

rptClientDoc.DatabaseController.LogonEx("dwcb12003", "xtreme", "sb", "pw");

//Create the logon propertybag for the connection we wish to use

CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag logonDetails = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();

logonDetails.Add("Auto Translate", -1);

logonDetails.Add("Connect Timeout", 15);

logonDetails.Add("Data Source", "dwcb12003");

logonDetails.Add("General Timeout", 0);

logonDetails.Add("Initial Catalog", "Orders");

logonDetails.Add("Integrated Security", "True");

logonDetails.Add("Locale Identifier", 1033);

logonDetails.Add("OLE DB Services", -5);

logonDetails.Add("Provider", "SQLOLEDB");

logonDetails.Add("Use Encryption for Data", 0);

logonDetails.Add("Owner", "dbo"); // schema

//Create the QE (query engine) propertybag with the provider details and logon property bag.

CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag QE_Details = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();

QE_Details.Add("Database DLL", "crdb_ado.dll");

QE_Details.Add("QE_DatabaseName", "Orders");

QE_Details.Add("QE_DatabaseType", "OLE DB (ADO)");

QE_Details.Add("QE_LogonProperties", logonDetails);

QE_Details.Add("QE_ServerDescription", "dwcb12003");

QE_Details.Add("QE_SQLDB", "True");

QE_Details.Add("SSO Enabled", "False");

QE_Details.Add("Owner", "dbo");

CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();

CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnInfo;

CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos oldConnInfos;

oldConnInfos = rcd.DatabaseController.GetConnectionInfos(null);

for (int I = 0; I < oldConnInfos.Count; I++)

{

oldConnInfo = oldConnInfos<i>;

newConnInfo.Attributes = QE_Details;

newConnInfo.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;

rcd.DatabaseController.ReplaceConnection(oldConnInfo, newConnInfo, null, CrystalDecisions.ReportAppServer.DataDefModel.CrDBOptionsEnum.crDBOptionDoNotVerifyDB);

}

}

Thanks again

Don

Answers (2)

Answers (2)

0 Kudos

See this thread for more info:

0 Kudos

Hi Scott,

What happens if you hard code ALL of the logon properties. This will verify the connection info is correct...

Also curious why you are using the clone method? It's only required, typically, if you are changing the connection type. If you are simply setting the log on info, but same type of data source, then using AG's sample is all that is required.

Thank you

Don

Former Member
0 Kudos

Hi Don,

These reports I used were created by Crystal Report XI and they still use Access database, in our current project we already upgrade our database to SQL Server, so I have to change the connection information dynamically while viewing the reports. Although I don't use the clone method, I still get same result, the logon dialog is always displayed. please see the following debugging information:

logInfo.ConnectionInfo.DatabaseName "DatabaseSPR"

You can see I already set the connection information correctly, but after I execute the method tbl.ApplyLogOnInfo(logInfo), the connection information in tbl is not changed:

tbl.LogOnInfo.ConnectionInfo.DatabaseName "d:
cp
cp30
test
working.mdb"

I don't know why I can't change the connection information in ReportDocument.

Thanks!

Former Member
0 Kudos

hi, Don

If I change the connection information in these reports, it will work but I have to change the database connection information dynamically because we must deploy these report to other macnines not development machines.

Thanks!