Crystal报告:无法打开连接
Crystal report: failed to open connection
我的数据库是远程 Mysql 数据库,我可以通过多台 PC 访问我的应用程序的 crystal 报告,但其中一台 PC 出现问题,即使我安装了 mysql 连接器并创建了与我的数据库的连接,该连接使用 ODBC 成功。但是当我加载报告时它显示一条消息 "Failed to open connection"
我使用了以下代码进行手动连接:
cI.ServerName = "Driver={MySQL ODBC 5.3 Unicode Driver};Server=x.x.x.x;Port=3306;Option=3;";
cI.DatabaseName = "dbName";
cI.UserID = "username";
cI.Password = "pass";
foreach (IConnectionInfo info in report.DataSourceConnections)
{
info.SetConnection(cI.ServerName, cI.DatabaseName, cI.UserID, cI.Password);
}
foreach (ReportDocument sub in report.Subreports)
{
foreach (IConnectionInfo info in sub.DataSourceConnections)
{
info.SetConnection(cI.ServerName, cI.DatabaseName, cI.UserID, cI.Password);
}
}
我得到这个异常:
System.Runtime.InteropServices.COMException (0x800002F4): Failed to open the connection.
Failed to open the connection.
temp_32398d30-5e82-45f2-a356-0abdad3ba4c5 5168_1588_{1AF659C8-D14D-479F-B268-51AD72B9420A}.rpt
at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.SetTableLocation(ISCRTable CurTable, ISCRTable NewTable)
at CrystalDecisions.CrystalReports.Engine.Table.set_Location(String value)
at School.UserInterface.StudentApp.PrintStudentInformation.connect(ReportDocument report)
at School.UserInterface.StudentApp.PrintStudentInformation.PrintStudentInformation_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
经过几天的努力,我设法解决了问题,结果我不得不在出现这个问题的 PC 上安装 MySQL ODBC 32 位版本,即使那台 PC 已经有 MySQL 已安装 ODBC,但它是 64 位版本。
所以,如果有人遇到类似的问题,那么我建议如果您的 PC 是 64 位 PC,您应该安装两个版本的 MySQL ODBC。
我遇到了同样的问题,经过 2 天的研究,我终于能够通过添加以下代码解决问题
reportDoc.SetDatabaseLogon(userId, password, serverName, database, true);
reportDoc.VerifyDatabase();
reportDoc.Refresh();
我的数据库是远程 Mysql 数据库,我可以通过多台 PC 访问我的应用程序的 crystal 报告,但其中一台 PC 出现问题,即使我安装了 mysql 连接器并创建了与我的数据库的连接,该连接使用 ODBC 成功。但是当我加载报告时它显示一条消息 "Failed to open connection"
我使用了以下代码进行手动连接:
cI.ServerName = "Driver={MySQL ODBC 5.3 Unicode Driver};Server=x.x.x.x;Port=3306;Option=3;";
cI.DatabaseName = "dbName";
cI.UserID = "username";
cI.Password = "pass";
foreach (IConnectionInfo info in report.DataSourceConnections)
{
info.SetConnection(cI.ServerName, cI.DatabaseName, cI.UserID, cI.Password);
}
foreach (ReportDocument sub in report.Subreports)
{
foreach (IConnectionInfo info in sub.DataSourceConnections)
{
info.SetConnection(cI.ServerName, cI.DatabaseName, cI.UserID, cI.Password);
}
}
我得到这个异常:
System.Runtime.InteropServices.COMException (0x800002F4): Failed to open the connection.
Failed to open the connection.
temp_32398d30-5e82-45f2-a356-0abdad3ba4c5 5168_1588_{1AF659C8-D14D-479F-B268-51AD72B9420A}.rpt
at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.SetTableLocation(ISCRTable CurTable, ISCRTable NewTable)
at CrystalDecisions.CrystalReports.Engine.Table.set_Location(String value)
at School.UserInterface.StudentApp.PrintStudentInformation.connect(ReportDocument report)
at School.UserInterface.StudentApp.PrintStudentInformation.PrintStudentInformation_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
经过几天的努力,我设法解决了问题,结果我不得不在出现这个问题的 PC 上安装 MySQL ODBC 32 位版本,即使那台 PC 已经有 MySQL 已安装 ODBC,但它是 64 位版本。 所以,如果有人遇到类似的问题,那么我建议如果您的 PC 是 64 位 PC,您应该安装两个版本的 MySQL ODBC。
我遇到了同样的问题,经过 2 天的研究,我终于能够通过添加以下代码解决问题
reportDoc.SetDatabaseLogon(userId, password, serverName, database, true);
reportDoc.VerifyDatabase();
reportDoc.Refresh();