.Net Windows 服务抛出 EventType clr20r3 system.data.sqlclient.sql 错误
我有一个 .Net/c# 2.0 windows 服务。入口点包含在 try catch 块中,该块通知我出现问题并允许服务继续正常运行,但当我查看服务器的应用程序事件日志时,我看到许多导致服务终止的“EventType clr20r3”错误不料。 catch 块有一个“catch(Exception ex)”并且不会重新抛出异常。
每个 sql 命令都是“CommandType.StoredProcedure”类型,并使用 SqlDataReader 执行。这些存储过程调用在 99% 的时间内都能正确运行,并且都经过了彻底的单元测试、分析和质量检查。我另外将这些调用包装在 try catch 块中,只是为了确定,并且仍然遇到这些未处理的异常。
这仅在我们的生产环境中,不能在我们的开发或登台环境中复制(即使在重负载下)。
为什么我的错误处理无法捕获这个特定的错误?是否有办法捕获有关问题根本原因的更多详细信息?
以下是事件日志的示例:
EventType clr20r3,P1 RDC.OrderProcessorService, P2 1.0.0.0, P3 4ae6a0d0, P4系统.数据, P5 2.0.0.0、P6 4889聋哑人、 P7 2490, P8 2c, P9系统.data.sqlclient.sql, P10 无。
此外
订单处理程序服务意外终止。 它已经这样做了 1 次。 将在 60000 毫秒内采取以下纠正措施: 重新启动服务。
I have a .Net/c# 2.0 windows service. The entry point is wrapped in a try catch block that notifies me of problems and allows the service to continue operating normally yet when I look at the server's application event log I see a number of "EventType clr20r3" errors that are causing the service to die unexpectedly. The catch block has a "catch (Exception ex)" and does not rethrow the exception.
Each sql commands is of the type "CommandType.StoredProcedure" and are executed with SqlDataReader's. These sproc calls function correctly 99% of time and have all been thoroughly unit tested, profiled, and QA'd. I additionally wrapped these calls in try catch blocks just to be sure and am still experiencing these unhandled exceptions.
This only in our production environment and cannot be duplicated in our dev or staging environments (even under heavy load).
Why would my error handling not catch this particular error? Is there anyway to capture more detail as to the root cause of the problem?
Here is an example of the event log:
EventType clr20r3, P1 RDC.OrderProcessorService, P2 1.0.0.0, P3 4ae6a0d0, P4 system.data, P5 2.0.0.0, P6 4889deaf, P7 2490, P8 2c, P9 system.data.sqlclient.sql, P10 NIL.
Additionally
The Order Processor service terminated unexpectedly. It has done this 1 time(s). The following corrective action will be taken in 60000 milliseconds: Restart the service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从评论中回答。很高兴能提供帮助。 :)
Answer from comments. Glad to have helped. :)
此错误很可能发生在入口点以外的线程上。
您还需要以某种方式为后台线程定义异常处理。
如果您使用 WCF 来包装服务,则可以定义如何处理错误和其他异常。这就是您托管服务的方式吗?
编辑:如果您没有异步生成任何内容,并且它不是 WCF/etc 应用程序,请尝试处理 AppDomain.UnhandledException 并在那里记录详细错误。
This error is most likely happening on a thread other than your entry point.
You need to somehow define exception handling for your background threads as well.
If you are using WCF to wrap your service, you have the ability to define how faults and other exceptions are handled. Is this how you're hosting your service?
EDIT: If you aren't spawning anything asynchronously, and it's not a WCF/etc app, try handling AppDomain.UnhandledException and logging the detailed error there.