Print Page | Close Window

Runtime Connection to the Database server

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=71
Printed Date: 29 Apr 2024 at 3:30pm


Topic: Runtime Connection to the Database server
Posted By: Sreenivas
Subject: Runtime Connection to the Database server
Date Posted: 21 Dec 2006 at 4:33am
Hi,
 
Problem: Unable to Connect to Database at Runtime.
 
Reports are Created using a particular Database server and if we want to
change the database server still it connects to the previous database server only.  We would like to know how to connect to the other Database server having the same structure as of the initial one. We are using OLE DB (ADO) for the connection purpose. The Below given code is also used at the time of reports creation.
 
Code:

public void CrystalReportlogin(ReportDocument report)
{
ConnectionInfo connection = new CrystalDecisions.Shared.ConnectionInfo();
CrystalDecisions.Shared.TableLogOnInfo log = new
CrystalDecisions.Shared.TableLogOnInfo();
connection.DatabaseName =
ConfigurationManager.AppSettings["DataBaseName"].ToString();
connection.ServerName =
ConfigurationManager.AppSettings["ServerName"].ToString();
connection.UserID = ConfigurationManager.AppSettings["UserID"].ToString();
connection.Password =
ConfigurationManager.AppSettings["Password"].ToString();
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in
report.Database.Tables)
{
log = tbl.LogOnInfo;
log.ConnectionInfo = connection;
crvBlocksReceivedForTheMonth.LogOnInfo.Add(log);
}
}
 
Thanks & Regards,
Sreenivas Kaushik


-------------
S Kaushik



Replies:
Posted By: LeMike
Date Posted: 23 Dec 2006 at 10:28am
I suppose that you have actually checked that

ConfigurationManager.AppSettings["ServerName"].ToString();

is really giving you what you are expecting ..... ?  (Yes, silly question ... I know ... I hope !)


-------------
It's not because things are hard that we don't try them ... it's because we don't try them that they are hard. (Lucius Seneca)



Print Page | Close Window