SQL Server 离线时的客户端反馈
我们有一个非常以数据为中心的应用程序,它通常在连接有问题的网络上运行。
我们希望在数据库离线时向客户反馈,并显示某种警告屏幕 - 包含错误信息 - 直到网络恢复并且数据库再次可用。我想在数据库因任何原因不可用时显示相同的屏幕 - 即:服务停止、暂停、登录失败、网络关闭等。
我有一个处理 SQLClient.SQLException 的例程,然后解析 SQLErrors 并检查数字,问题是有大量不同的失败错误号,而我总是遗漏一些。
有没有一些简单、一致的方法可以检查数据库服务器是否离线或不可用?其他人如何处理这个问题而不让一些未处理的异常溜走?
干杯
We have a very data centric application, which is often run across networks with questionable connectivity.
We want to feedback to clients when the database is offline, and display some kind of warning screen - with error information - until the network comes back and the database is available again. I'd like to display the same screen whenever the database is unavailable for any reason - ie: service stopped, paused, login failure, network off, etc.
I have a routine handling SQLClient.SQLException, which I then parse for SQLErrors and check the numbers, problem is there are loads of different error numbers for failures and I keep missing some.
Is there some simple, consistent way i can check if the database server is offline or unavailable? How do others handle this without letting some unhandled exception slip through?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以轻松地仅捕获 sql 异常,如下所示:
you can easily catch only sql exceptions like this:
我尝试为需要检查连接的服务器创建带有连接字符串的
SqlConnection
对象,尝试Open()
此连接并在此处检查异常。但不确定这是最有效的...I'd try to create
SqlConnection
object with connection string for server I need to check connectivity to, try toOpen()
this connection and check for exceptions here. Not sure that's the most efficient, though...