C# 当会话断开时,.Net Crystal Report 打印应用程序在终端服务连接错误上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/602295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 09:55:21  来源:igfitidea点击:

.Net Crystal Report printing application running on termianal service connection errors when session is disconnected

c#crystal-reportsremote-desktop

提问by MrEdmundo

I have created a .Net application to run on an App Server that gets requests for a report and prints out the requested report.

我创建了一个 .Net 应用程序以在应用程序服务器上运行,该应用程序服务器获取报告请求并打印出请求的报告。

The C# application uses Crystal Reports to load the report and subsequently print it out.

C# 应用程序使用 Crystal Reports 加载报告并随后将其打印出来。

The application is run on Server which is connected to via a Remote Desktop connection under a particular user account (required for old apps). When I disconnect from the Remote Session the application starts raising exceptions such as:

该应用程序在特定用户帐户下通过远程桌面连接连接到的服务器上运行(旧应用程序需要)。当我与远程会话断开连接时,应用程序开始引发异常,例如:

Message: CrystalDecisions.Shared.CrystalReportsException: Load report failed

消息:CrystalDecisions.Shared.CrystalReportsException:加载报告失败

This type of error is never raised when the Remote Session is active. The server running the app is running Windows Server 2003, my box which creates the connection is Windows XP.

当远程会话处于活动状态时,永远不会引发此类错误。运行该应用程序的服务器运行的是 Windows Server 2003,我创建连接的机器是 Windows XP。

I appreciate this is fairly weird, however I cannot see any problem with the application deployment I have created.

我很欣赏这很奇怪,但是我看不到我创建的应用程序部署有任何问题。

Does anyone know what could be cause this issue?

有谁知道可能导致此问题的原因?

EDIT: I bit the bullet and created the application as a windows service, obviously this doesn't take long I just wasn't convinced it would solve the problem. Anyway it doesn't!!!

编辑:我咬紧牙关,将应用程序创建为 Windows 服务,显然这不会花很长时间,我只是不相信它会解决问题。反正没有!!!

I have also tried removing the multi-thread code that was calling the print function asynchronously. I did this in order to simply the app and narrow down the reason it could fail. Anyway, this didn't improve the situation either!

我还尝试删除异步调用打印函数的多线程代码。我这样做是为了简化应用程序并缩小它可能失败的原因。无论如何,这也没有改善情况!

EDIT: The two errors I get are:

编辑:我得到的两个错误是:

System.Runtime.InteropServices.COMException (0x80000201): Invalid printer specified. at CrystalDecisions.ReportAppServer.Controllers.PrintOutputControllerClass.ModifyPrinterName(String newVal) at CrystalDecisions.CrystalReports.Engine.PrintOptions.set_PrinterName(String value) at Dsa.PrintServer.Service.Service.PrintCrystalReport(Report report)

System.Runtime.InteropServices.COMException (0x80000201): 指定的打印机无效。在 CrystalDecisions.ReportAppServer.Controllers.PrintOutputControllerClass.ModifyPrinterName(String newVal) 在 CrystalDecisions.CrystalReports.Engine.PrintOptions.set_PrinterName(String value) 在 Dsa.PrintServer.Service.Service.PrintCrystalReport(Report report)

The printer isn't invalid, this is confirmed when 60 seconds later the time ticks and the report is printed successfully.

打印机不是无效的,这是在 60 秒后时间滴答并成功打印报告时确认的。

And

The request could not be submitted for background processing. 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.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 Dsa.PrintServer.Service.Service.PrintCrystalReport(Report report)

无法提交请求以进行后台处理。在 CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.GetLastPageNumber(RequestContext pRequestContext) 在 CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext) --- 内部异常堆栈跟踪结束 --- 在 CrystalDecisions.ReportAppServer.ConvertDotNetToErom.Throwdott在 CrystalDecisions.ReportSource.EromReportSourceBase.GetLastPageNumber(ReportPageRequestContext reqContext) 在 CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collat​​ed, Int32 startPageN, Int32 endPageN) 在 CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collat​​ed, Int32 startPageN, Int32 endPageN) 在 CrystalDecisions.CrystalReports.CrystalReports.Engine.FormatEngine.PrintToPrinter,整理,Int32 startPageN,

EDIT:

编辑:

I ran filemon to check if there were any access issue. At the point when the error occurs file mon reports

我运行 filemon 来检查是否有任何访问问题。在发生错误时 file mon 报告

Request: OPEN | Path: C:\windows\assembly\gac_msil\system\2.0.0.0__b77a5c561934e089\ws2_32.dll | Result: NOT FOUND | Other: Attributes Error

请求:打开 | 路径:C:\windows\assembly\gac_msil\system\2.0.0.0__b77a5c561934e089\ws2_32.dll | 结果:未找到 | 其他:属性错误

采纳答案by MrEdmundo

Our particular problem has been solved. Basically when the reports were created they were saved with information about printers. Basically a particular printer had been set for the report and saved.

我们的特殊问题已经解决。基本上,在创建报告时,它们会与有关打印机的信息一起保存。基本上已经为报告设置了一个特定的打印机并保存了。

This printer no longer exists which is why the report had started failing. Basically we had to open the report designer and remove any association with printers in the report.

这台打印机不再存在,这就是报告开始失败的原因。基本上我们必须打开报告设计器并删除与报告中打印机的任何关联。

回答by REA_ANDREW

If you create a window service wrapper for your application, it means that it will continue to run regardless of users logged in. It can also be set to start up automatically. I think that because you are using an actual application, and not a windows service it is not actually running once you logout of a session on the server.

如果为应用程序创建窗口服务包装器,则意味着无论用户登录如何,它都会继续运行。它也可以设置为自动启动。我认为,因为您使用的是实际应用程序,而不是 Windows 服务,所以一旦您注销服务器上的会话,它实际上就不会运行。

Here is an example on Code Project:

这是代码项目的示例:

http://www.codeproject.com/KB/system/WindowsService.aspx

http://www.codeproject.com/KB/system/WindowsService.aspx

回答by E.J. Brennan

Are you sure you are "disconnecting' you remote session as opposed to "logging off". I disconnect my sessions to a nt server 2003 all the time and everything to continues to run just fine. Logging off on the other hand will kill the apps running in that session.

你确定你是“断开”你的远程会话而不是“注销”。我一直断开我的会话到 nt server 2003,一切都继续运行得很好。另一方面注销会杀死应用程序在那个会话中运行。

What is your o/s server running?

你的操作系统服务器在运行什么?

回答by runxc1 Bret Ferrier

In Order to solve the problem that you have described you need to focus in on what your problem is.

为了解决您所描述的问题,您需要关注您的问题是什么。

I have recieved the Message: CrystalDecisions.Shared.CrystalReportsException: Load report failed a number of times and it is due to the fact that you can't access the report. Either it doesn't exist or in your situation the you are not connected to the machine. The error is not due to anything printing related.

我收到了消息:CrystalDecisions.Shared.CrystalReportsException:多次加载报告失败,这是因为您无法访问报告。要么它不存在,要么在您的情况下您没有连接到机器。错误不是由于任何与打印相关的事情。

回答by Paul Williams

We have encountered these errors several times in the past few years. Many times I wished for some more specific error message.

在过去的几年中,我们多次遇到这些错误。很多时候我希望得到一些更具体的错误信息。

First, I would verify that there aren't multiple Crystal Reports versions installed. In our expereince, we found that Crystal Reports 9.0 doesn't seem to play well with 10. Uninstalling version 9 seemed to help some of our customers. If both are installed, I highlly recommend uninstalling both, then re-installing Crystal Reports 10.

首先,我将验证没有安装多个 Crystal Reports 版本。根据我们的经验,我们发现 Crystal Reports 9.0 似乎与 10 的配合不佳。卸载版本 9 似乎对我们的一些客户有所帮助。如果两者都安装,我强烈建议卸载两者,然后重新安装 Crystal Reports 10。

One of our earliest Crystal Reports errors was the dreaded "The request could not be submitted for background processing." Reports would work fine for a while, then suddenly they would stop. After looking at the code, I found a place where we were not disposing of a ReportDocument. Correctly disposing this document fixed the issue.

我们最早的 Crystal Reports 错误之一是可怕的“无法提交请求以进行后台处理”。报告会正常工作一段时间,然后突然停止。查看代码后,我发现我们没有处理 ReportDocument 的地方。正确处理此文档可解决此问题。

Lately, we hit a spat of "The request could not be submitted for background processing." and "Invalid Printer" errors. One customer's server had several network printers defined by IP address. Printing would work just fine for a while, then suddenly, bam, the customer got the "Invalid Printer" error and called our support.

最近,我们遇到了“无法提交请求以进行后台处理”的争论。和“无效的打印机”错误。一位客户的服务器有多个由 IP 地址定义的网络打印机。打印可以正常工作一段时间,然后突然,,客户收到“打印机无效”错误并致电我们的支持。

A fellow developer fixed the "Invalid Printer" problem by doing all of the following things:

一位开发人员通过执行以下所有操作解决了“无效打印机”问题:

  1. Edit and save the .rpt file in Visual Studio 2005. We had been keeping the report format compatible with Crystal Reports 9, because we wanted our changes to be distributable to our customers still using older versions.
  2. Save Crystal Reports files with the "No Printer" option. From the Visual Studio 2005 menu, select Crystal Reports/Design/Printer Setup, then select the "No Printer" check box.
  3. We changed a formula that displayed "Page N of M" from something strange like this:
  1. 在 Visual Studio 2005 中编辑并保存 .rpt 文件。我们一直保持报表格式与 Crystal Reports 9 兼容,因为我们希望我们的更改可以分发给仍在使用旧版本的客户。
  2. 使用“无打印机”选项保存 Crystal Reports 文件。从 Visual Studio 2005 菜单中,选择 Crystal Reports/Design/Printer Setup,然后选中“No Printer”复选框。
  3. 我们改变了一个显示“M 的第 N 页”的公式,从这样的奇怪的东西:

"Page " + Left (CStr (PageNumber), Length (CStr (PageNumber)) - 3) +
" of " + Left (CStr (TotalPageCount), Length (CStr (TotalPageCount)) - 3)
"Page " + Left (CStr (PageNumber), Length (CStr (PageNumber)) - 3) +
" of " + Left (CStr (TotalPageCount), Length (CStr (TotalPageCount)) - 3)

to this:

对此:

"Page " + CStr(PageNumber,0) + " of " + CStr(TotalPageCount,0)

Unfortunately, I have no idea which (any or all) of the above actions may fixed the error. I say "may", because for all I know, the error magically went away because of some IT network change.

不幸的是,我不知道上述哪些(任何或全部)操作可以修复错误。我说“可能”,因为据我所知,由于某些 IT 网络更改,错误神奇地消失了。

Finally, have you read this white paper?While it did not necessarily solve our problems, it was very interesting.

最后,您是否阅读了 这份白皮书?虽然它不一定能解决我们的问题,但它非常有趣。

回答by David Sitsky

I had an obscure issue that was similar to this, except it was a (shock-horror) automation issue with Excel. I found the application worked fine when I had my remote desktop session connected, but once disconnected, it would give automation errors relating to the default printer.

我有一个与此类似的晦涩问题,但它是 Excel 的(令人震惊的)自动化问题。当我连接远程桌面会话时,我发现该应用程序运行良好,但一旦断开连接,就会出现与默认打印机相关的自动化错误。

I believe the issue relates to how the default printer is set when you connect with remote desktop. Assuming you have a .rdp file for initiating your remote desktop session, if you edit it, then select the "Local Resources" tab, you can see whether or not you share your local printer on the remote session.

我相信这个问题与您连接远程桌面时如何设置默认打印机有关。假设您有一个用于启动远程桌面会话的 .rdp 文件,如果您对其进行编辑,然后选择“本地资源”选项卡,您可以查看是否在远程会话中共享您的本地打印机。

If it is enabled, this means when you connect, your local default printer becomes the default printer on the remote machine. When you disconnect, your application's default printer will still possibly refer to the now unavailable default printer from your local machine.

如果启用,这意味着当您连接时,您的本地默认打印机将成为远程机器上的默认打印机。当您断开连接时,您的应用程序的默认打印机仍可能会引用您本地机器上现在不可用的默认打印机。

You should be able to solve this, by ensuring you don't share your local printer, by deselecting the Printer checkbox from the "Local Resources" tab.

通过从“本地资源”选项卡中取消选中打印机复选框,确保不共享本地打印机,您应该能够解决此问题。

An easier solution would be to disable "printer redirection" on the server. See https://serverfault.com/questions/5646/how-do-i-disable-remote-printers-using-group-policyfor more information.

一个更简单的解决方案是在服务器上禁用“打印机重定向”。有关更多信息,请参阅https://serverfault.com/questions/5646/how-do-i-disable-remote-printers-using-group-policy

回答by David Sitsky

If you are looking in detail how to

如果您正在详细查看如何

add checkboxes into crystal reports on a boolean feild and if the boolean field is false

将复选框添加到关于布尔字段的水晶报告中,如果布尔字段为假

uncheck else check the checkbox look at this article

取消选中否则选中复选框看看这篇文章

http://checkboxcrystalreport.blogspot.com/2009/07/printing-checkbox-in-crystal-report-for.html

http://checkboxcrystalreport.blogspot.com/2009/07/printing-checkbox-in-crystal-report-for.html