Question

I have an app that runs on system startup that needs to talk to the local SQL Server 2005 installation. I'm using the ServiceController class to wait for it to enter the "Running" state, and most times this works fine. 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.

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?

Was it helpful?

Solution

You could always use the System.Data.Sql.SqlDataSourceEnumerator and check for the local instance.

On the plus, you can also discover version information with the enumerator.

OTHER TIPS

You could just catch the exception and retry until it works...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top