简体   繁体   English

为什么在Crystal Reports方法ExportToDisk中无法打开连接

[英]Why am I getting failed to open connection in Crystal Reports method ExportToDisk

I have a report that users say was working. 我有一个用户说正在运行的报告。 This application is new to me and Crystal Reports is new to me. 该应用程序对我来说是新的,而Crystal Reports对我来说是新的。 The database was backed up and restored to a new SqlServer. 已备份数据库并将其还原到新的SqlServer。 The orphaned users were relinked and the report code (shown below) changed to point to the new server. 孤立的用户被重新链接,报告代码(如下所示)更改为指向新服务器。 Now it get's failed to connect error. 现在,它无法连接错误。 the report is run from c# code. 该报告是从C#代码运行的。 Here is the code that calls the report, followed by the values at the point the code threw the exception. 这是调用报告的代码,其后是引发异常的点的值。

        private void laborRptByJobBtn_Click(object sender, EventArgs e)
    {
        if (rptFolderDialog.ShowDialog() == DialogResult.OK)
        {
            try
            {
                CrystalDecisions.CrystalReports.Engine.ReportDocument rptObj = new LaborRptByJob();
                CrystalDecisions.Shared.TableLogOnInfo tliEZIS = new TableLogOnInfo();


                tliEZIS.TableName = rptObj.Database.Tables[0].Name;
                tliEZIS.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["DatabaseServerName"];
                tliEZIS.ConnectionInfo.DatabaseName = "EZIS";
                tliEZIS.ConnectionInfo.UserID = "EZIS";
                tliEZIS.ConnectionInfo.Password = "EZIS";
                rptObj.Database.Tables[0].ApplyLogOnInfo(tliEZIS);
                rptObj.SetParameterValue("JobNumber", division.Text.Trim());
                string testPath = rptFolderDialog.SelectedPath + "\\Job " + division.Text.Trim() + " - Labor Report.pdf";
                rptObj.ExportToDisk(ExportFormatType.PortableDocFormat, testPath);
                //rptObj.ExportToDisk(ExportFormatType.PortableDocFormat, rptFolderDialog.SelectedPath + "\\Job#: " + division.Text.Trim() + " - Labor Report.pdf");
            }
            catch (NotSupportedException ex)
            {
                MessageBox.Show(ex.Message, ex.Source);
            }
        }
    }

}

I am getting this seemingly interesting error message in the watch list upon exception: 出现异常时,我在监视列表中收到此看似有趣的错误消息:

        'rptObj.Database.Tables[0].Location' threw an exception of type 'System.InvalidCastException'   error CS1012: Too many characters in character literal  

I know that implies the use of single quotes to set a string but I looked through the code and didn't find a direct setting of the location parameter at all or any single quotes. 我知道这意味着使用单引号设置字符串,但是我查看了代码,但没有找到直接设置所有或任何单引号的location参数的方法。 Also at the same time I set a watch to location and got this 同时,我将手表放在位置上并得到了

        rptObj.Database.Tables[0].Location  "LaborReportView"   string

other values are: 其他值为:

ServerName = "\\\\appdev02\\mssql2017dev"
DatabaseName = "EZIS"
UserId = "EZIS"
Testpath = "\\\\Mac\\Home\\Desktop\\Job 2849 - Labor Report.pdf"

In the watch list there are several rows of invalidcastexceptions such as one on Location and one on Name. 在监视列表中,有几行invalidcastexceptions,例如在Location上的一行和在Name上的一行。 I have used SSMS to verify that the EZIS login to \\appdev02\\mssql2017dev EZIS database exists with the same password and has rights to the view. 我已使用SSMS验证到\\ appdev02 \\ mssql2017dev EZIS数据库的EZIS登录是否具有相同的密码并且具有对该视图的权限。

Well I found the answer with help. 好吧,我在帮助下找到了答案。 The error message was couldn't connect so I spent time looking at why that might be. 错误消息无法连接,所以我花了一些时间看为什么会这样。 The real problem was the source of the data was a view and the view was broken. 真正的问题是数据源是一个视图,并且该视图已损坏。 In the old database the view linked to a separate server using openquery(). 在旧数据库中,该视图使用openquery()链接到单独的服务器。 In the new server the two databases were on the same server so the "link" was not available. 在新服务器中,两个数据库位于同一服务器上,因此“链接”不可用。 A simple change to a fully qualified name made it work. 只需对完全限定的名称进行更改即可使用。

I'm posting this in spite of the fact that I'm embarrassed I didn't try to run the view much earlier in the diagnosis of the problem. 尽管我很尴尬,但我并没有在诊断问题的过程中尽早地运行该视图,但我仍在发布此信息。

Prime learning (relearning) never trust an error message to indicate exactly what the problem is. 首要学习(再学习)从不相信错误消息来确切说明问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM