Search

Tuesday, April 14, 2009

Get Servername dynamatically in Crystal report

private void GetReport(string rptpath)
{
try
{
string dbname = "";
string servername = "";
string UserId = "";
string pwd = "";
servername = ConfigurationManager.AppSettings["ServerName"];
dbname = ConfigurationManager.AppSettings["DatabaseName"];
UserId = ConfigurationManager.AppSettings["UserId"];
pwd = ConfigurationManager.AppSettings["Password"];
crConnectionInfo.ServerName = servername;
crConnectionInfo.DatabaseName = dbname;
crConnectionInfo.UserID = UserId;
crConnectionInfo.Password = pwd;

crReportDocument.Load(Server.MapPath(rptpath));
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;

for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables[i];
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);

crTable.Location = dbname + ".dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);

CrystalReportViewer1.ReportSource = crReportDocument;
}
}
catch (Exception ex)
{
throw ex;
}
}

in Web.config we have to write below syntex




No comments:

Blog Archive

Contributors