With some slower machines that our application runs on (which is in the windows startup folder), when the machine is Rebooted and autologged on, the SQL Server service is still in a starting up state when my application is launched. (SqlServer 2005)
What I've done to counter this is to Check the Service state (MSSQL$idealsql) and wait until the service is Running.
Public Function isServiceRunning() As Boolean
Dim theServices() As System.ServiceProcess.ServiceController
Dim theservice As System.ServiceProcess.ServiceController
theServices = System.ServiceProcess.ServiceController.GetServices
Dim running As Boolean
For Each theservice In theServices
If String.Equals(theservice.ServiceName, mServiceName, StringComparison.OrdinalIgnoreCase) Then
running = (theservice.Status = ServiceProcess.ServiceControllerStatus.Running)
Exit For
End If
Next
Return running
End Function
This is returning the correct result once the service comes online, but SQLServer takes a little while before it is fully operational after the service has been started.
Update
This process is only used on application startup.
PseudoCode.
Check Service running (this process)
Check Database exists
false -> create database
true -> perform any updates required to structures etc
Continue into main program execution
End Update
I then need to check for the presence of our Database (that gets dynamically created if it's not present), which I do via looking as sysdatabases, and finding if our database is there, but once again, it takes a little bit before all the databases are actually brought online.
I also found some additional code to check for the creation of the TempDB and get the date that it was created to determine when the service came online.
SELECT crdate AS StartTime FROM sys.sysdatabases WHERE name = 'tempdb'
According to the EventVwr, TempDB is the First Database brought online.
Is there a proper way to determine that SQLServer is fully online, and all databases have been started up?
Whilst the code shown is VB.Net i'm not too concerned with the language, moreso just the proper way to determine if the Database Server is fully online.