Skip to Content
0
Former Member
Mar 01, 2011 at 09:03 PM

Override Driver from DBF file to SQL server, "Failed to load database info"

30 Views

Hi there,

I've a crystal report that was loading DBF file, but I want to change the connection to SQL at run time via RAS, below is the code I found from the SAP forum, but I'm keep getting "Failed to load database info".. What could be wrong here?

Thank you,

CrystalDecisions.CrystalReports.Engine.ReportDocument myReport2 = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

protected void Page_Load(object sender, EventArgs e) {

try {

myReport2.Load( Server.MapPath( "CRDBase.rpt" ) );

ISCDReportClientDocument reportClientDocument = myReport2.ReportClientDocument;

ISCDReportClientDocument rcd;

rcd = reportClientDocument;

reportClientDocument.DatabaseController.LogonEx( "SQL2008R2", "CR", "smisreader", "pass@word1" );

//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", "SQL2008R2" );

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

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

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

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", "CR" );

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

QE_Details.Add( "QE_LogonProperties", logonDetails );

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

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;

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

}

CrystalReportViewer2.ReportSource = myReport2;

}

catch( Exception ex ) {

}

}