J
Jeff
Hi -
I'm building a VB.NET Windows application with an MSDE database.
Anticipating the possibility that the MSDE service may have been stopped
outside of my app, I'm trying to code a way to start it when my app is
launched. I can't seem to get the code to wait for MSDE to start before
continuing (the next step is opening a connection). My development machine
is WinXP Pro.
I'm using the ServiceController class to start and check the service. When
my code (see below) runs, the ex3 exception is never raised. The MessageBox
(MessageBox.Show(strStat)) Shows "Running" so the service started
successfully. If I click the MessageBox OK button after about 5 seconds,
the ensuing connection succeeds. If I click the MessageBox button without
waiting, the ensuing connection fails.
What am I doing wrong and/or what's the right way to do this??
Thanks for your help.
Here's my code:
Dim strStat As String = "Unknown"
Dim svc As New ServiceController
svc.ServiceName = "MSSQL$" & strInstance
If svc.Status = ServiceControllerStatus.Stopped Then
Try
svc.Start()
svc.WaitForStatus(ServiceControllerStatus.Running)
Catch ex3 As Exception
MessageBox.Show("Unable to start database service.",
strAppName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
If svc.Status = ServiceControllerStatus.Running Then
strStat = "Running"
ElseIf svc.Status = ServiceControllerStatus.Stopped Then
strStat = "Stopped"
End If
MessageBox.Show(strStat)
frmMain.conSC = New SqlConnection(strConn)
frmMain.conSC.ConnectionString = strConn
frmMain.conSC.Open()
- Jeff
I'm building a VB.NET Windows application with an MSDE database.
Anticipating the possibility that the MSDE service may have been stopped
outside of my app, I'm trying to code a way to start it when my app is
launched. I can't seem to get the code to wait for MSDE to start before
continuing (the next step is opening a connection). My development machine
is WinXP Pro.
I'm using the ServiceController class to start and check the service. When
my code (see below) runs, the ex3 exception is never raised. The MessageBox
(MessageBox.Show(strStat)) Shows "Running" so the service started
successfully. If I click the MessageBox OK button after about 5 seconds,
the ensuing connection succeeds. If I click the MessageBox button without
waiting, the ensuing connection fails.
What am I doing wrong and/or what's the right way to do this??
Thanks for your help.
Here's my code:
Dim strStat As String = "Unknown"
Dim svc As New ServiceController
svc.ServiceName = "MSSQL$" & strInstance
If svc.Status = ServiceControllerStatus.Stopped Then
Try
svc.Start()
svc.WaitForStatus(ServiceControllerStatus.Running)
Catch ex3 As Exception
MessageBox.Show("Unable to start database service.",
strAppName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
If svc.Status = ServiceControllerStatus.Running Then
strStat = "Running"
ElseIf svc.Status = ServiceControllerStatus.Stopped Then
strStat = "Stopped"
End If
MessageBox.Show(strStat)
frmMain.conSC = New SqlConnection(strConn)
frmMain.conSC.ConnectionString = strConn
frmMain.conSC.Open()
- Jeff