We have deployed our ASP.NET application on the target machine. The application contains some crystal reports (rpt files) and while invoking we pass on the database connection details. It is working fine on the test server. But on the target server, the crystal report while being invoked asks for the database connection details. It asks four parameters as Server, database, user id, password. Out of these, the first two text boxes are disabled. The Server editbox shows the ip of the server that I passed. But the database parameter is shown blank. I was expecting the initial catalog that I set in the connection string. user id is showing the user id I passed.
The config file has the connection string like:
<add name = "reportdb" connectionString = "Data Source=172.16.7.85;Initial Catalog=reportdb;Persist Security Info=True;User ID=sa;Password=sa;" providerName = "System.Data.SqlClient"/>
While setting the values we get thes from the config and set to the report through a method as:
public int GenerateReport(CrystalReportViewer crystalReportViewer, string userid, string password, string server,string databaseName)
{
reportDoc = new ReportDocument();
subreportDocument = new ReportDocument();
Sections sections;
SubreportObject subreportObject;
ReportObjects reportObjects;
ConnectionInfo connectionInfo = new ConnectionInfo();
TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
Database database;
Tables tables;
CrystalDecisions.CrystalReports.Engine.Table crTable;
connectionInfo.DatabaseName = databaseName;
connectionInfo.UserID = userid;
connectionInfo.Password = password;
connectionInfo.ServerName = server;
reportDoc.Load(reportName);
database = reportDoc.Database;
tables = database.Tables;
tableLogOnInfo.ConnectionInfo = connectionInfo;
for (int i = 0; i < tables.Count; i++)
{
crTable = tables[i];
tableLogOnInfo = crTable.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
crTable.ApplyLogOnInfo(tableLogOnInfo);
}
sections = reportDoc.ReportDefinition.Sections;
foreach (Section crSection in sections)
{
reportObjects = crSection.ReportObjects;
foreach (ReportObject crReportObject in reportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
subreportObject = (SubreportObject)crReportObject;
subreportDocument = subreportObject.OpenSubrepor开发者_Python百科t(subreportObject.SubreportName);
database = subreportDocument.Database;
tables = database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in tables)
{
tableLogOnInfo = aTable.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
aTable.ApplyLogOnInfo(tableLogOnInfo);
}
}
}
}
foreach (DataRow dataRow in reportDetailDataTable.Rows)
{
//because it'll be null for optional parameter
////if (!string.IsNullOrEmpty(dataRow["Parameter value"].ToString()))
////{
ParameterFieldDefinition parameterFieldDefinition = null;
ParameterValues parameterValues = null;
ParameterDiscreteValue parmeterDiscreteValue = null;
parameterValues = new ParameterValues();
parameterFieldDefinition = reportDoc.DataDefinition.ParameterFields[dataRow[0].ToString()];
parmeterDiscreteValue = new ParameterDiscreteValue();
parmeterDiscreteValue.Value = dataRow[2].ToString();
parameterValues.Add(parmeterDiscreteValue);
parameterFieldDefinition.ApplyCurrentValues(parameterValues);
}
if (reportDoc.Database.Tables.Count > 0)//i.e only if report has table
{
reportDoc.Database.Tables[0].ApplyLogOnInfo(tableLogOnInfo);
}
crystalReportViewer.ReportSource = reportDoc;
return -1;
}
So, I feel there is some issue with crystal report or the SQL native client. Can somebody help?
What if you fetch the connection property from the web.config itself. Split it as required or add key value in
<appsettings add key="Datasource" value="19.168.10.1"> </appsettings>
and so on.
精彩评论