on 03-01-2011 9:03 PM
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 ) {
}
}
See if using the utility described in the KB [1553921 - Is there a utility that would help in writing database logon code?|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333533353333333933323331%7D.do] will help.
Best way to use the above is to create a simple report using connection to SQL. Then run the report in the above utility and see the code generated.
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.