如何使用动态连接 crystal 报告
how can use dynamic connection crystal report
我在我的应用程序中使用动态连接
当我在我的应用程序中使用本地数据库时,我的报告没有任何问题
但是当我使用另一个数据库(不在本地)时收到报告我的应用程序崩溃
我使用 c# 和 wpf
try
{
ReportDocument rd = new ReportDocument();
string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name;
rd.Load(path);
rd.RecordSelectionFormula = this.GetFormula;
switch (report_name)
{
case "full.rpt":
{
break;
}
}
}
catch
{
MessageBox.Show("error");
}
我该怎么办?
try
{
ReportDocument rd = new ReportDocument();
//////////////////////
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
rd.Load(System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name);
RegistryKey ConnectionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\forosh");
string server = (string)ConnectionKey.GetValue("ServerName");
crConnectionInfo.ServerName = server;
RegistryKey ConnectionKey2 = Registry.CurrentUser.CreateSubKey("SOFTWARE\forosh");
string db = (string)ConnectionKey2.GetValue("DbName");
crConnectionInfo.DatabaseName = db;
crConnectionInfo.IntegratedSecurity = true;
CrTables = rd.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crv.ViewerCore.ReportSource = rd;
crv.ViewerCore.RefreshReport();
//////////////////////////////
string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name;
rd.Load(path);
rd.RecordSelectionFormula = this.GetFormula;
switch (report_name)
{
case "full.rpt":
{
break;
}
case "formul.rpt":
{
break;
}
}
crv.ViewerCore.ReportSource = rd;
}
catch {
}
}
我在我的应用程序中使用动态连接
当我在我的应用程序中使用本地数据库时,我的报告没有任何问题
但是当我使用另一个数据库(不在本地)时收到报告我的应用程序崩溃
我使用 c# 和 wpf
try
{
ReportDocument rd = new ReportDocument();
string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name;
rd.Load(path);
rd.RecordSelectionFormula = this.GetFormula;
switch (report_name)
{
case "full.rpt":
{
break;
}
}
}
catch
{
MessageBox.Show("error");
}
我该怎么办?
try
{
ReportDocument rd = new ReportDocument();
//////////////////////
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
rd.Load(System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name);
RegistryKey ConnectionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\forosh");
string server = (string)ConnectionKey.GetValue("ServerName");
crConnectionInfo.ServerName = server;
RegistryKey ConnectionKey2 = Registry.CurrentUser.CreateSubKey("SOFTWARE\forosh");
string db = (string)ConnectionKey2.GetValue("DbName");
crConnectionInfo.DatabaseName = db;
crConnectionInfo.IntegratedSecurity = true;
CrTables = rd.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crv.ViewerCore.ReportSource = rd;
crv.ViewerCore.RefreshReport();
//////////////////////////////
string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\" + this.report_name;
rd.Load(path);
rd.RecordSelectionFormula = this.GetFormula;
switch (report_name)
{
case "full.rpt":
{
break;
}
case "formul.rpt":
{
break;
}
}
crv.ViewerCore.ReportSource = rd;
}
catch {
}
}