Crystal reports 在ASP.NET中打开Crystal报表时出错
我试图打开一个水晶报告在我的网站,但它给出了一个错误 这是我尝试过的代码Crystal reports 在ASP.NET中打开Crystal报表时出错,crystal-reports,crystal-reports-xi,Crystal Reports,Crystal Reports Xi,我试图打开一个水晶报告在我的网站,但它给出了一个错误 这是我尝试过的代码 protected void report_view(object sender, EventArgs e) { ReportDocument cryRpt = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = n
protected void report_view(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("C:\\Report1.rpt");
crConnectionInfo.ServerName = "local";
crConnectionInfo.DatabaseName = "MyEmployees";
crConnectionInfo.UserID = "MYLAPTOP\\HOME";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
这是CrystalReportViwer中显示的错误
Failed to open the connection. Failed to open the connection. Report1 {1222DD0B-C24E- 4E66-8EE1-7ED7F5F0D6B4}.rpt
我将visual studio 2010与Crystal Reports 11一起使用,您在声明连接详细信息时似乎缺少密码。尝试添加它:
crConnectionInfo.ServerName = "local";
crConnectionInfo.DatabaseName = "MyEmployees";
crConnectionInfo.UserID = "MYLAPTOP\\HOME";
crConnectionInfo.Password = "Password"; //Swap with real password of course
确保所有文件路径和文件名也正确
或者,您可以查看数据库是否没有密码保护。就我个人而言,我怀疑服务器名称,数据库是本地的,因此我将服务器名称设置为本地的,与SqlServer中的相同。UserID也与SqlServer中的相同。UserNamesetDatabaseLogon()方法对我有效,谢谢@Conrad Lotz