简体   繁体   English

检测SQL Server重新启动

[英]Detecting SQL Server reboot

My c# console app runs on an different machine than my SQL Server 2014. I use ado.net to connect to it. 我的c#控制台应用程序与SQL Server 2014在不同的计算机上运行。我使用ado.net连接到它。 How can I detect if the sql server automatically reboots after installing windows updates? 安装Windows更新后,如何检测sql服务器是否自动重新启动? On my client application I use SystemEvents_SessionEnding but this does not help me. 在我的客户端应用程序上,我使用SystemEvents_SessionEnding,但这对我没有帮助。

I read about connection resiliency, but this seems also not to solve this problem. 我阅读了有关连接弹性的信息,但这似乎也不能解决该问题。

Is there a specific ado.net event I can capture? 我可以捕获特定的ado.net事件吗? Creating an app on the server sending UDP is not my prefered solution, aswell I dont want to use ping etc. 在发送UDP的服务器上创建应用不是我偏爱的解决方案,而且我也不想使用ping等。

I'm really looking for something like an event to react on. 我真的在寻找像事件这样的反应。

eg the notification services: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlnotificationinfo(v=vs.110).aspx 例如,通知服务: https : //msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlnotificationinfo(v=vs.110).aspx

Thanks! 谢谢!

If you want to see if the server is down or not you can use Ping Class. 如果要查看服务器是否关闭,可以使用Ping Class。

using System.Net.NetworkInformation;

var ping = new Ping();
var reply = ping.Send("SqlServerIP");

if (reply.Status == IPStatus.Success)
{
    //server is available
}
else
{
    //server is down
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM