我的数据库受密码保护。每当我使用CrystalReportViewer
加载我的水晶报告文件时,它会提示输入数据库登录..
有没有办法让我消除这个提示?让它自动登录?
答案 0 :(得分:1)
如果您的意思是在运行时,那么this article会帮助您
以下是代码,以防上述链接被禁用:
//report is just some ReportDocument.
CrystalDecisions.CrystalReports.Engine.Tables tables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
CrystalDecisions.Shared.TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo.ServerName = "myserverIPOrHostname";
tableLogOnInfo.ConnectionInfo.UserID = "MYUSER";
tableLogOnInfo.ConnectionInfo.Password = "MYPASSWORD";
table.ApplyLogOnInfo(tableLogOnInfo);
}