Crystal报告“数据库登录失败”错误? [英] Crystal reports "database logon failed"error?
本文介绍了Crystal报告“数据库登录失败”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用C#开发了Windows Form Application。它的印刷票据使用水晶报告。但不是账单打印。 数据库登录失败错误。怎么能解决这个问题? plzz帮助我。
输出:
I am developed Windows Form Application using C#. Its printed bill for use the crystal report. But not bill print. comes "database logon failed" error. how can solve this problem? plzz help me.
Output:
'POS_System.exe' (CLR v4.0.30319: POS_System.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'POS_System.exe' (CLR v4.0.30319: POS_System.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.ReportSource\13.0.3500.0__692fbea5521e1304\CrystalDecisions.ReportSource.dll'. Cannot find or open the PDB file.
Exception thrown: 'CrystalDecisions.CrystalReports.Engine.LogOnException' in CrystalDecisions.CrystalReports.Engine.dll
The program '[15476] POS_System.exe: Program Trace' has exited with code 0 (0x0).
The program '[15476] POS_System.exe' has exited with code -1 (0xffffffff).
我尝试过:
使用ODBC连接方法。所以,我想使用用户ID和密码登录SQL服务器数据库。不是Windows身份验证方法。
What I have tried:
using the ODBC connection method. So, I want to use User ID and Password for login SQL server database. Not windows authentication method.
推荐答案
确保您已按如下方式添加对Crystal Reports的引用;
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.Windows.Forms
添加以下内容使用语句;
Ensure you have added references to Crystal Reports as follows;
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.Windows.Forms
Add the following using statements;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
以下代码用于打开Crystal Report&应用登录信息。
The below code is used to open a Crystal Report & apply the Logon information.
// create the report object
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("<Path & file name of the report>");
// create the connection information
ConnectionInfo conRpt = new ConnectionInfor();
conRpt.ServerName = "DB Server Name";
conRpt.DatabaseName = "DB Name";
conRpt.UserID = "User name";
conRpt.Password = "Password";
// apply connection information to the report tables
Tables rptTables = rptDoc.Database.Tables;
for(int i = 0; i < rptTables.Count; i++)
{
Table rptTable = rptTables[i];
TableLogOnInfo tblInfo = rptTable.LogOnInfo;
tblInfo.ConnectionInfo = conRpt;
// next table
}
// if the report contains sub reports, you will need to set the connection info there too
if(rptDoc.SubReports.Count > 0)
{
for(int i = 0; i < rptDoc.Subreports.Count; i++)
{
using(ReportDocument rptSub = rptDoc.OpenSubReport(rptDoc.SubReports[i].Name))
{
Tables rptTables = rptSub.Database.Tables;
for(int i = 0; i < rptTables.Count; i++)
{
Table rptTable = rptTables[i];
TableLogOnInfo tblInfo = rptTable.LogOnInfo;
tblInfo.ConnectionInfo = conRpt;
// next table
}
rptSub.Close();
}
}
}
// Show Report in Viewer - you can also send direct to a printer if required
// Note; do not call refresh report on the ReportViewer control as this will undo all of the above
frmReportViewer.ReportSource = rptDoc;
亲切的问候
Kind Regards
这篇关于Crystal报告“数据库登录失败”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文