-
February 24th, 2004, 01:12 AM
#1
how to dynamically change connection string in crystal reports at runtime?
plz. tell me
how to dynamically change connection string in crystal reports at runtime?
Like i can get the connection string from an xml file at runtime, and modify its value anytime.
thanks
-
February 24th, 2004, 06:21 AM
#2
I normally do it this way:
Code:
private bool ConnectDB( )
{
Database crDatabase;
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
ConnectionInfo crConnectionInfo;
try
{
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = (string)Application["DataSource"];
// the tables for the report are always at the global database
crConnectionInfo.DatabaseName = "mydatabase";
crConnectionInfo.UserID = (string)Application["User"];
crConnectionInfo.Password = (string)Application["Password"];
//Get the tables collection from the report object
crDatabase = m_oRpt.Database;
crTables = crDatabase.Tables;
//Apply the logon information to each table in the collection
foreach( CrystalDecisions.CrystalReports.Engine.Table crTable in crTables )
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo( crTableLogOnInfo );
// test the database connection
bool bTest = crTable.TestConnectivity();
if( !bTest )
{
Response.Write( "Failed to Logon Table: " + crTable.Name + "<br>" );
}
}
}
catch( CrystalDecisions.CrystalReports.Engine.LogOnException ex )
{
Response.Write( "Error while Database Logon. Please check Logon inforamtion. <br>" );
Response.Write( "Username: " + (string)Application["User"] +
"<br>Database:mydatabasel<br>DataSource: " +
(string)Application["DataSource"] + "<br>" );
Response.Write( ex.Message + "<br>" + ex.Source + "<br>" + ex.StackTrace + "<br>" + ex.TargetSite.Name );
return( false );
}
catch( Exception /*ex*/ )
{
return( false );
}
return( true );
}
Hope this helps
-
April 4th, 2004, 09:50 AM
#3
i did, but still its loading from the database, which was specified at design time.
Kindly tell me how to do it.
Thanks again
Last edited by Farhad; April 5th, 2004 at 11:31 PM.
-
April 5th, 2004, 02:18 AM
#4
mhm, strange thing. When you save your report do you set the option "Save report with data" to true or to false?
-
April 5th, 2004, 11:28 PM
#5
it never asked me to save report with data?
how to set that?
-
April 25th, 2005, 06:56 AM
#6
Re: how to dynamically change connection string in crystal reports at runtime?
I've had some weired behavior with the Database Connection on installations. Things got better with later versions of the Merge Moduls.
It's worth a try!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|