473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Waiting to Start a Service

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
Nov 21 '05 #1
4 2218
Hi Jeff,

The code seems to be OK. Based on my experience, even the status is
"running", MSDE service still may be executing some initializtion jobs and
refuse to outside connection. I suggest you may put the Connection.open in
a loop, when found it failed, wait for seconds and then open the connection
again. This should be a proper solution for the problem.

Luke

Nov 21 '05 #2
OK Luke -

I've resolved the problem by looping/sleeping until a connection succeeds.

But shouldn't there be a way for code to determine when MSDE is able to
_accept_ a connection?? Without that, it seems to me that knowing that
Status is Running is pretty worthless.

- Jeff
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:AY**************@cpmsftngxa10.phx.gbl...
Hi Jeff,

The code seems to be OK. Based on my experience, even the status is
"running", MSDE service still may be executing some initializtion jobs and refuse to outside connection. I suggest you may put the Connection.open in
a loop, when found it failed, wait for seconds and then open the connection again. This should be a proper solution for the problem.

Luke

Nov 21 '05 #3
The status property is not believable during the MSDE service's Statup
process. Unfortunately, it is the only property we can access. The only way
is to try connection till success.

Luke

Nov 21 '05 #4
Thanks Luke.

"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:ra**************@cpmsftngxa10.phx.gbl...
The status property is not believable during the MSDE service's Statup
process. Unfortunately, it is the only property we can access. The only way is to try connection till success.

Luke

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Keith | last post by:
I am writing a web service that sends work to a system that gets it's work via XML files. This system looks for files in a particular directory, processes the file, then leaves a response file in...
3
by: Ted | last post by:
In doing a db2 list applications show detail, I have 320 entries applications. Of those sometimes all of them are "UOW Waiting." Ususally there are from 1 to 4 marked UOW Executing. The rest...
3
by: mphanke | last post by:
Hi, I would like to implement a windows service which forks a configurable number of threads which all siten to the same port and reply to requests of different clients. How would I implement...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
3
by: JN | last post by:
Hello, I am trying to write a program or service that will run in the background and wait for a particular program to start, when it does I want something else to occur such as a message box. I...
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
0
by: =?Utf-8?B?QmlsbEI=?= | last post by:
This is a tough one... My Windows Service app periodically performs some processing on new entries to a SQL Server database table. It uses a simple System.Timer to call the Elapsed event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.