[英]How can I tell that SQL Server is started and ready to use?
I have an app that runs on system startup that needs to talk to the local SQL Server 2005 installation.我有一个在系统启动时运行的应用程序,它需要与本地 SQL Server 2005 安装进行通信。 I'm using the ServiceController class to wait for it to enter the "Running" state, and most times this works fine.
我正在使用 ServiceController class 等待它进入“正在运行”state,而且大多数情况下都可以正常工作。 However, sometimes on a cold boot, my first query fails, saying that it couldn't log on the current user.
但是,有时在冷启动时,我的第一个查询失败,说它无法登录当前用户。
It sounds like a race condition, but I figured my WaitForStatus call was supposed to resolve it.这听起来像是一个竞争条件,但我认为我的 WaitForStatus 调用应该可以解决它。
Is there a better way to make sure it's really-truly running?有没有更好的方法来确保它真正运行? Should I just throw in an extra sleep and assume it's long enough?
我应该多睡一觉并假设它足够长吗?
You could just catch the exception and retry until it works...您可以捕获异常并重试,直到它起作用...
You could always use the System.Data.Sql.SqlDataSourceEnumerator and check for the local instance.您始终可以使用System.Data.Sql.SqlDataSourceEnumerator并检查本地实例。
On the plus, you can also discover version information with the enumerator.此外,您还可以使用枚举器发现版本信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.