在VB.NET中运行的监视程序 [英] Watcher running in VB.NET

查看:60
本文介绍了在VB.NET中运行的监视程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有访客
我创建了一个连接到数据库(Sql服务器)的应用程序.但是当sql server服务已停止时,我的应用程序仍在运行.
我的目的是当sql停止服务时,我的应用程序应显示一条消息以告知用户有关连接的信息.我想知道在VB.NET中有什么工具可以监视出现上述错误的应用程序.

最好的问候,

Hi all visitor
i created one application that connect to database(Sql server).but when the sql server service has been stop.my application still running.
My purpose is that when the sql stop service, My application should display a message to tell user about the connection. I want to know in VB.NET has any tools to watch my application when there is something wrong like i have mentioned above.

Best Regards,

推荐答案

您创建了一个线程,该线程用于检查您的sql连接是否处于活动状态.如果还不存在,则显示给用户的消息并采取其他措施.
You Create a thread which is use to check certain period your sql connection is alive or not. if not alive then you display message for user and take other action.


要添加到Rakesh所说的内容中...

没有工具可以为您进行监视.

您可以运行一个后台线程,每隔一段时间就会"ping"服务器.基本上,它只会尝试打开与数据库的连接并运行一个非常小的查询,然后关闭它的连接.如果可行,则该服务正在运行.如果没有,那么您就得到了答案...

不要打开与数据库的连接并将其保持打开状态,以确保应用程序的生命!

可能有人说您需要使用服务管理器类来检查SQL Server服务的状态.这样做的问题是,您需要比普通用户更多的权限来执行此操作,并且您需要知道SQL Server服务实例的确切名称.如果您在同一服务器上运行多个SQL实例,则名称将更改.
To add to what Rakesh said...

There is no tool that will do the monitoring for you.

You could run a background thread that will "ping" the server every so often. Basically, it would just try and open a connection to the database and run a very small query, then close it''s connection. If this works, then the service is running. If not, well you''ve got your answer...

DO NOT OPEN A CONNECTION TO THE DATABASE AND KEEP IT OPEN FOR THE LIFE OF YOUR APPLICATION!

There may be someone who says that you need to use the Service Manager classes to check the state of the SQL Server service. The problem with this is that you need more than normal user permissions to do this and you would need to know the exact name of the SQL Server service instance. If you are running multiple instances of SQL on the same server, the name will change.


这篇关于在VB.NET中运行的监视程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆