什么是编程测试SQL Server连接的最佳方式? [英] What's the best way to test SQL Server connection programmatically?

查看:117
本文介绍了什么是编程测试SQL Server连接的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发将被解雇每次5分钟,以检查是否SQL服务器(10至12)的列表是建立和运行一个程序。

I need to develop a single routine that will be fired each 5 minutes to check if a list of SQL Servers (10 to 12) are up and running.

我可以尝试获得在服务器中的每一个简单的查询,但是这意味着我必须建立在每个服务器中的表,视图或存储过程,即使我使用任何已经取得SP,我需要有一个注册的用户在每个服务器上了。服务器不在同一物理位置,以便具有这些要求将是一个复杂的任务。有没有办法从C#一条SQL Server只是平?

I can try to obtain a simple query in each one of the servers but this means that I have to create a table, view or stored procedure in every server, even if I use any already made SP I need to have a registered user in each server too. The servers are not in the same physical location so having those requirements would be a complex task. Is there a way to simply "ping" from C# one SQL Server?

在此先感谢!

推荐答案

执行 SELECT 1 ,并检查的ExecuteScalar返回1。

Execute SELECT 1 and check if ExecuteScalar returns 1.

这篇关于什么是编程测试SQL Server连接的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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