SQL Server状态监视器

发布于 2024-11-01 09:11:25 字数 162 浏览 4 评论 0原文

我的应用程序同时连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

太阳男子 2024-11-08 09:11:25

我认为你应该使用 WMI (使用 ServiceController 类(带有 this 构造函数)。 下面的示例

假设您的应用程序是用 c# 编写的:

ServiceController sc = new ServiceController("MSSQLSERVER", serverName); 
string status = sc.Status.ToString();

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#:

ServiceController sc = new ServiceController("MSSQLSERVER", serverName); 
string status = sc.Status.ToString();
耳钉梦 2024-11-08 09:11:25

“此代码不应影响速度
应用程序或 SQL 的开销
服务器”

:为了了解给定远程服务或进程的当前状态,您必须将消息序列化到网络上,等待响应,反序列化响应并对其采取行动。所有这些需要所有涉及的机器进行一些工作和资源,

如果不经常调用,可能不会以任何可测量的方式影响目标服务器。

但是,该工作可能在调用者的后台线程中完成, 一个href="http://msdn.microsoft.com/en-us/library/ms162547.aspx" rel="nofollow">SMO(SQL Server 管理对象) 连接到远程服务器并执行许多操作您可以通过 SQL 管理工具执行任何操作,因为它们也使用 SMO 来发挥其魔力。它是一个非常简单的 API,并且在正确的人手中可以非常强大,

毫不奇怪,SMO 确实要求您对您的盒子拥有适当的权限。如果您没有/不能拥有足够的权限,您可能需要要求友好的 SQL amin 团队发布一个简单的数据源,公开您需要的一些数据。

HTH。

"This code should not affect the speed
of application or a overhead to SQL
server"

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.

起风了 2024-11-08 09:11:25

连接(验证连接)或连接失败(验证无连接)时,应用程序中会产生一些开销,但您可以通过异步检查来避免等待时间。

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.

绝影如岚 2024-11-08 09:11:25

我们使用以下 SQL 查询来检查特定数据库的状态

SELECT 'myDatabase status is:' AS Description, ISNULL((select state_desc FROM sys.databases WITH (NOLOCK) WHERE name ='myDatabase'),'Not Found') AS [DBStatus]

应该有很少的开销,特别是与后台或异步线程等最佳实践结合使用时

We use the following SQL query to check the status of a particular database

SELECT 'myDatabase status is:' AS Description, ISNULL((select state_desc FROM sys.databases WITH (NOLOCK) WHERE name ='myDatabase'),'Not Found') AS [DBStatus]

This should have very little overhead, especially when paired with best practices like background or asynchronous threads

韬韬不绝 2024-11-08 09:11:25

全面披露,我是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文