SQL Server状态监视器
我的应用程序同时连接到 3 个 SQL 服务器和 5 个数据库。我需要在状态栏上显示状态 {running|stopped|not find}
。
我可以在这里使用任何想法/代码示例吗?此代码不应影响应用程序的速度或 SQL Server 的开销。
菩提
My application connects to 3 SQL servers and 5 databases simultaneously. I need to show statuses {running|stopped|not found}
on my status bar.
Any idea/code sample that I can use here? This code should not affect the speed of application or a overhead to SQL server.
Buddhi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为你应该使用 WMI (使用 ServiceController 类(带有 this 构造函数)。 下面的示例
假设您的应用程序是用 c# 编写的:
I think you should use WMI (using the ServiceController class (with this constructor). You basically query the server where the sql server resides and check its status.
The example below is assuming your application is written in c#:
:为了了解给定远程服务或进程的当前状态,您必须将消息序列化到网络上,等待响应,反序列化响应并对其采取行动。所有这些需要所有涉及的机器进行一些工作和资源,
如果不经常调用,可能不会以任何可测量的方式影响目标服务器。
但是,该工作可能在调用者的后台线程中完成, 一个href="http://msdn.microsoft.com/en-us/library/ms162547.aspx" rel="nofollow">SMO(SQL Server 管理对象) 连接到远程服务器并执行许多操作您可以通过 SQL 管理工具执行任何操作,因为它们也使用 SMO 来发挥其魔力。它是一个非常简单的 API,并且在正确的人手中可以非常强大,
毫不奇怪,SMO 确实要求您对您的盒子拥有适当的权限。如果您没有/不能拥有足够的权限,您可能需要要求友好的 SQL amin 团队发布一个简单的数据源,公开您需要的一些数据。
HTH。
This is a Schroedinger's Cat scenario: in order to know the current status of a given remote service or process, you must serialize a message onto the network, await a response, de-serialize the response and act upon it. All of which will require some work and resources from all machines involved.
However, that work might be done in a background thread on the caller and if not called too often, may not impact the target server(s) in any measurable way.
You can use SMO (SQL Server Management Objects) to connect to a remote server and do pretty much anything you can do through the SQL admin tools since they use SMO to work their magic too. It's a pretty simple API and can be very powerful in the right hands.
SMO does, unsurprisingly, require that your have appropriate rights to the boxes you want to monitor. If you don't/can't have sufficient rights, you might want to ask your friendly SQL amin team to publish a simple data feed exposing some of the data you need.
HTH.
连接(验证连接)或连接失败(验证无连接)时,应用程序中会产生一些开销,但您可以通过异步检查来避免等待时间。
There will be some overhead within your application when connecting (verifying connection) or failing to connect (verifying no connection) but you can prevent waiting time, by checking this asynscronously.
我们使用以下 SQL 查询来检查特定数据库的状态
应该有很少的开销,特别是与后台或异步线程等最佳实践结合使用时
We use the following SQL query to check the status of a particular database
This should have very little overhead, especially when paired with best practices like background or asynchronous threads
全面披露,我是 Cotega 的创始人
如果您对执行此操作的服务感兴趣,我们的服务允许监控SQL Server 正常运行时间和性能。此外,您还可以设置数据库不可用、性能下降、数据库大小或用户计数问题发生等时的通知。
Full Disclosure, I am the founder of Cotega
If you are interested in a service to do this, our service allows for monitoring of SQL Server uptime and performance. In addition you can set notifications for when the database is not available, performance degrades, database size or user count issues occur, etc.