【发布时间】:2019-09-24 04:36:57
【问题描述】:
我创建了一个使用 SQL Server 存储过程作为数据源的 Crystal Report。存储过程有一个参数。当下面的代码运行时,我在 obj.PrintToPrinter 行得到“数据库登录失败”。
如果我从报告中删除存储过程并将其替换为存储过程中使用的相同表并使用相同的参数,则不会出错。报告打印没有问题!
任何帮助将不胜感激,我真的很想为我们的报告使用存储过程。谢谢!
ReportDocument obj = new ReportDocument();
string m_rptname = "C:\\Reports\\MyReport.rpt";
obj.Load(m_rptname);
obj.SetParameterValue(0, "123456");
foreach (Table tbl in obj.Database.Tables)
{
TableLogOnInfo tli = tbl.LogOnInfo;
tli.ConnectionInfo.ServerName = "myServer";
tli.ConnectionInfo.UserID = "myUser";
tli.ConnectionInfo.Password = "myPass";
tli.ConnectionInfo.DatabaseName = "myDB";
tbl.ApplyLogOnInfo(tli);
}
//The line below is where the error happens for stored proc only
obj.PrintToPrinter(2, false, 0, 0);
obj.Close();
obj.Dispose();
【问题讨论】:
标签: c# sql-server winforms stored-procedures crystal-reports