Я пытался загрузить Crystal Report на windows Server 2012 R2 из IIS. Я получил ошибку Не удалось открыть соединение. MA723DT 2608_14160_ {B2777DB7-D4BD-4E31-8748-7E70DE55C132} .rpt , но работает на той же машине из Visual Studio при отладке приложения
private void GetReport(string EmpID, string StartDate, string EndDate, string Conn, string Cmpid)
{
try {
TableLogOnInfos TableLogOnInfos = new TableLogOnInfos();
TableLogOnInfo TableLogOnInfo = new TableLogOnInfo();
ConnectionInfo ConnectionInfo = new ConnectionInfo();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
Tables Tables;
ReportDocument report = new ReportDocument();
string FileName = "~/MA723BA.rpt";
report.Load(Server.MapPath(FileName));
if (Conn != "")
{
string ConnString = ConfigurationManager.ConnectionStrings[Conn].ConnectionString;
if (ConnString.ToLower().StartsWith("metadata="))
{
System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(ConnString);
ConnString = efBuilder.ProviderConnectionString;
builder.ConnectionString = ConnString;
ConnectionInfo.ServerName = builder.DataSource;
ConnectionInfo.DatabaseName = builder.InitialCatalog;
ConnectionInfo.UserID = builder.UserID;
ConnectionInfo.Password = builder.Password;
Tables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in Tables)
{
TableLogOnInfo = table.LogOnInfo;
TableLogOnInfo.ConnectionInfo = ConnectionInfo;
table.ApplyLogOnInfo(TableLogOnInfo);
}
}
}
ParameterRangeValue myParameterRangeValue = new ParameterRangeValue();
myParameterRangeValue.StartValue = StartDate;
myParameterRangeValue.EndValue = EndDate;
report.SetParameterValue(0, EmpID);
report.SetParameterValue(1, myParameterRangeValue);
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.DataBind();
}
catch(Exception er)
{
throw;
}
}