数据库登录失败

时间:2016-10-09 10:10:33

标签: c# sql sql-server winforms crystal-reports

这个例外发生在客户端Pc上,而晶体报告在生产Pc上工作正常

 CrystalDecisions.CrystalReports.Engine.LogOnException: Database logon failed. ---> System.Runtime.InteropServices.COMException: Database logon failed.
at       CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.GetLastPageNumber(RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext)
--- End of inner exception stack trace ---
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.HandleException(Exception exception)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
at CButtonTestForm.frm_sale1.print(Int32 op1) in D:\CButton\CButtonTestForm\frm_sale1.vb:line 221
at CButtonTestForm.frm_sale1.cmd_print_Click(Object sender, EventArgs e) in D:\CButton\CButtonTestForm\frm_sale1.vb:line 1253
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,    Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr   wparam, IntPtr lparam)

enter image description here

当我点击打印按钮时,它会显示错误登录失败:

    Function print(ByVal op1 As Integer) As Integer
    adpt = New SqlDataAdapter("SELECT orderdetail.sr, orderdetail.prid, orderdetail.sp, orderdetail.qty, orderdetail.total FROM orderdetail where OrderID=" & cmbinv.Text, cn)
    ds = New DataSet()
    adpt.Fill(ds, "orderdetail")
    rpt.SetDataSource(ds)
    ' Dim Report1 As New saleinv
    '   Report1.DataDefinition.FormulaFields.Item("Text7").Text = txttoken1.Text
    rpt.SetParameterValue("Token", txttoken1.Text)
    frmsalerpt.CrystalReportViewer1.ReportSource = rpt
    rpt.PrintToPrinter(1, True, 0, 0)
 End Function

1 个答案:

答案 0 :(得分:0)

填写数据库服务器信息,如下所示:

CrystalDecisions.Shared.TableLogOnInfo crLogonInfo;
crLogonInfo = this.crystalReport.Database.Tables[0].LogOnInfo;
crLogonInfo.ConnectionInfo.ServerName = SystemConfiguration.DBInstance.SQLServerName;
crLogonInfo.ConnectionInfo.UserID = SystemConfiguration.DBInstance.SQLUserID;
crLogonInfo.ConnectionInfo.Password = SystemConfiguration.DBInstance.SQLPassword;
crLogonInfo.ConnectionInfo.DatabaseName = SystemConfiguration.DBInstance.SQLDatabaseName;
this.crystalReport.Database.Tables[0].ApplyLogOnInfo(crLogonInfo);