views:

95

answers:

2

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?

+5  A: 

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

Telos
The best way to tell it's 'really-truly running' is to run a query so this has to be the best option.
Dave Webb
+3  A: 

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.

toast
I will probably try this first. Thanks!
Coderer