我正在使用Windows 7,SQL Server 2000和VS 2008 / Crystal Report XI。
点击GetReport按钮后,我收到了以下错误。
登录失败。详细信息:ADO错误代码:0x源:用于SQL Server的Microsoft OLE DB提供程序说明:用户“sa”的登录失败。 SQL状态:42000本机错误:文件C中的错误:\ Users \ bahadur \ AppData \ Local \ Temp \ Total_Sales_Comparision {C4649F80-D1F7-4AED-A4B1-0B8EF83996C6} .rpt:无法连接:登录参数不正确。 块引用
我的C#代码低于
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = "BRAVEALI-PC";
crConnectionInfo.DatabaseName = "SCM_TEST";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "myDB Password";
ReportDocument report = new ReportDocument();
report.Load(@"D:\Project's\SCM Reports\Total_Sales_Comparision.rpt");
report.SetParameterValue("@invcm_date_from", Convert.ToDateTime (TextBox4.Text));
report.SetParameterValue("@invcm_date_to", Convert .ToDateTime(TextBox5.Text));
CrystalReportViewer1.ReportSource = report;
//CrystalReportViewer1.RefreshReport();
此致
勇敢的阿里
答案 0 :(得分:0)
你从未对你的crConnectionInfo对象做过任何事情......你没有把它绑回到你的报告对象上。
它为您提供了错误的登录信息,因为您从未设置过登录信息。
答案 1 :(得分:0)
使用此代码设置登录信息,
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
crConnectionInfo.ServerName = "Servername";
crConnectionInfo.DatabaseName = "Database";
crConnectionInfo.UserID = "Userid";
crConnectionInfo.Password = "password";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
或只是使用
yourreport.setdatabaselogon("username","Password","servername","databasename");