473,795 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ServiceControll er class to start and check the service. When
my code (see below) runs, the ex3 exception is never raised. The MessageBox
(MessageBox.Sho w(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 ServiceControll er
svc.ServiceName = "MSSQL$" & strInstance

If svc.Status = ServiceControll erStatus.Stoppe d Then
Try
svc.Start()
svc.WaitForStat us(ServiceContr ollerStatus.Run ning)

Catch ex3 As Exception
MessageBox.Show ("Unable to start database service.",
strAppName, MessageBoxButto ns.OK, MessageBoxIcon. Error)

End Try

End If

If svc.Status = ServiceControll erStatus.Runnin g Then
strStat = "Running"
ElseIf svc.Status = ServiceControll erStatus.Stoppe d Then
strStat = "Stopped"
End If

MessageBox.Show (strStat)

frmMain.conSC = New SqlConnection(s trConn)
frmMain.conSC.C onnectionString = strConn
frmMain.conSC.O pen()
- Jeff
Nov 21 '05 #1
4 2249
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******@onlin e.microsoft.com > wrote in message
news:AY******** ******@cpmsftng xa10.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******@onlin e.microsoft.com > wrote in message
news:ra******** ******@cpmsftng xa10.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
1699
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 the same directory. What is the best way to wait for the reponse file? Is there a better way than going into the following loop? while(!System.IO.File.Exists(reponseFile) { System.Threading.Thread.Sleep(1000); }
3
37923
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 are still waiting. What is meant by "waiting"? We have set TCPCOMMMGR to 4 (16 CPUs). We have increased IOCLEANERS and IOSERVERS, which had been set to low. Still the "waiting". Thanks in advance,
3
3317
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 something like this? Martin
12
2374
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 head. Natuarally it will not work. I expect it to use up all resources looping, which will not allow the process to complete. The process takes about 60 seconds, because the .bat file it is calling is rebuilding mulitple .NET solutions and projects...
3
1483
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 am not sure how to do the waiting game (sleep is no good, neither is a loop). Any help is appreciated. JN
6
4206
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 time, but occasionally after a system startup (where the service doing the starting of the other is automatically started by Windows XP) the ServiceController's Start() method fails to start the other service. It is probably throwing an...
7
7236
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 this error. I want to restart my windows service every time the COM object throws an error. I use System.ServiceProcess.ServiceController to stop and start my service. But there is one thing I do not understand:
4
21766
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 webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
0
1855
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 handler (which contains the processing code) every minute. The processing itself usually takes no more than a few seconds. Even so, I have a boolean set in the event handler when I'm currently processing information so that only one thread is...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.