这样是必须的,水晶报表在预览时会进行身份验证需要用代码处理,如下:
//数据库登录绑定
TableLogOnInfo logOnInfo = new TableLogOnInfo();
//从web.config中获取logOnInfo参数信息
string a, b, c, d;
//获取ServerName
a = ConfigurationManager.AppSettings["ServerName"];
//获取DatabaseName
b = ConfigurationManager.AppSettings["DatabaseName"];
//获取UserId
c = ConfigurationManager.AppSettings["UserID"];
//获取password
d = ConfigurationManager.AppSettings["Password"];
//设置logOnInfo参数
logOnInfo.ConnectionInfo.ServerName = a;
logOnInfo.ConnectionInfo.DatabaseName = b;
logOnInfo.ConnectionInfo.UserID = c;
logOnInfo.ConnectionInfo.Password = d;
customerReport.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
//绑定数据源
crystalReportViewer.ReportSource = customerReport;
我现在做的功能是脱离crystalReportViewer来展示,因为那个太丑了。对浏览器还有兼容限制,我现在处理方法是先生成pdf文件,然后用流量器调用PDF。这样方便预览和打印!
如需探讨加我Q:495840292