473,385 Members | 1,930 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,385 software developers and data experts.

Service depends on SQL Server

I have a Windows service that is having trouble starting up at boot time.
It requires SQL Server to start up. I have added MSSQLSERVER to the service
dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
made no difference. I log exceptions to the eventlog which tell me the
following error, abridged:

Login failed for user 'xxxxxx'.
at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
<snip>

I'm thinking I need to catch this exception in a loop a few times at service
startup for a long enough time for SQL Server to completely spin up.
Anybody else have other ideas? The service is written in C#.

-- Alan

Nov 16 '05 #1
9 1781
Try playing with the "Recovery" tab parameters.

You still want your service dependent on MSSQLSERVER. If I remember
correctly, the SQLSERVERAGENT service is not started Automatically.

Dave
"Alan Pretre" <al********@newsgroup.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a Windows service that is having trouble starting up at boot time.
It requires SQL Server to start up. I have added MSSQLSERVER to the
service
dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
made no difference. I log exceptions to the eventlog which tell me the
following error, abridged:

Login failed for user 'xxxxxx'.
at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
<snip>

I'm thinking I need to catch this exception in a loop a few times at
service
startup for a long enough time for SQL Server to completely spin up.
Anybody else have other ideas? The service is written in C#.

-- Alan

Nov 16 '05 #2
Hi,

You can set the dependency in code. The code snippet below is from a
service that I wrote that assures that SQL Server is running before it
starts. After I run InstallUtil on my service MSSQLSERVER is listed in the
depended on tab in the services window. When I reboot or start from a
command line I have no problems. You should not have to code any retry loops
or take any special action in your code:

private void InitializeComponent()
{
....
//
// service
//
this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.service.DisplayName = "Xxxxx";
this.service.ServiceName = "Xxxxx";
this.service.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
....
}

--Richard

"Alan Pretre" wrote:
I have a Windows service that is having trouble starting up at boot time.
It requires SQL Server to start up. I have added MSSQLSERVER to the service
dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
made no difference. I log exceptions to the eventlog which tell me the
following error, abridged:

Login failed for user 'xxxxxx'.
at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
<snip>

I'm thinking I need to catch this exception in a loop a few times at service
startup for a long enough time for SQL Server to completely spin up.
Anybody else have other ideas? The service is written in C#.

-- Alan

Nov 16 '05 #3
I would try Richard's solution before doing anything else.

This looks like it will work.

Nice Richard!
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Hi,

You can set the dependency in code. The code snippet below is from a
service that I wrote that assures that SQL Server is running before it
starts. After I run InstallUtil on my service MSSQLSERVER is listed in
the
depended on tab in the services window. When I reboot or start from a
command line I have no problems. You should not have to code any retry
loops
or take any special action in your code:

private void InitializeComponent()
{
....
//
// service
//
this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.service.DisplayName = "Xxxxx";
this.service.ServiceName = "Xxxxx";
this.service.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
....
}

--Richard

"Alan Pretre" wrote:
I have a Windows service that is having trouble starting up at boot time.
It requires SQL Server to start up. I have added MSSQLSERVER to the
service
dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
made no difference. I log exceptions to the eventlog which tell me the
following error, abridged:

Login failed for user 'xxxxxx'.
at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
<snip>

I'm thinking I need to catch this exception in a loop a few times at
service
startup for a long enough time for SQL Server to completely spin up.
Anybody else have other ideas? The service is written in C#.

-- Alan

Nov 16 '05 #4
Using dependencies may work in a situation where SQL server and your service
are on the same machine. But what about a distributed environment where SQL
server is on a separate server?

"Yoshi" wrote:
I would try Richard's solution before doing anything else.

This looks like it will work.

Nice Richard!
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Hi,

You can set the dependency in code. The code snippet below is from a
service that I wrote that assures that SQL Server is running before it
starts. After I run InstallUtil on my service MSSQLSERVER is listed in
the
depended on tab in the services window. When I reboot or start from a
command line I have no problems. You should not have to code any retry
loops
or take any special action in your code:

private void InitializeComponent()
{
....
//
// service
//
this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.service.DisplayName = "Xxxxx";
this.service.ServiceName = "Xxxxx";
this.service.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
....
}

--Richard

"Alan Pretre" wrote:
I have a Windows service that is having trouble starting up at boot time.
It requires SQL Server to start up. I have added MSSQLSERVER to the
service
dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
made no difference. I log exceptions to the eventlog which tell me the
following error, abridged:

Login failed for user 'xxxxxx'.
at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
at
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
<snip>

I'm thinking I need to catch this exception in a loop a few times at
service
startup for a long enough time for SQL Server to completely spin up.
Anybody else have other ideas? The service is written in C#.

-- Alan


Nov 16 '05 #5
Yes in this case however I know that SQL Server is installed on this test
machine.

In the general case though this is why I was thinking of putting my startup
access in a retry loop. It seems like this would work for a local or remote
SQL Server. I was looking for more input from others....

-- Alan
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Using dependencies may work in a situation where SQL server and your service are on the same machine. But what about a distributed environment where SQL server is on a separate server?

"Yoshi" wrote:
I would try Richard's solution before doing anything else.

This looks like it will work.

Nice Richard!
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Hi,

You can set the dependency in code. The code snippet below is from a
service that I wrote that assures that SQL Server is running before it
starts. After I run InstallUtil on my service MSSQLSERVER is listed in the
depended on tab in the services window. When I reboot or start from a
command line I have no problems. You should not have to code any retry loops
or take any special action in your code:

private void InitializeComponent()
{
....
//
// service
//
this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.service.DisplayName = "Xxxxx";
this.service.ServiceName = "Xxxxx";
this.service.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
....
}

--Richard

"Alan Pretre" wrote:

> I have a Windows service that is having trouble starting up at boot time.> It requires SQL Server to start up. I have added MSSQLSERVER to the
> service
> dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't> help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which> made no difference. I log exceptions to the eventlog which tell me the> following error, abridged:
>
> Login failed for user 'xxxxxx'.
> at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> isInTransaction)
> at
> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec> tionString options, Boolean& isInTransaction)
> at System.Data.SqlClient.SqlConnection.Open()
> <snip>
>
> I'm thinking I need to catch this exception in a loop a few times at
> service
> startup for a long enough time for SQL Server to completely spin up.
> Anybody else have other ideas? The service is written in C#.
>
> -- Alan
>
>
>
>


Nov 16 '05 #6
Running a loop will consume too much CPU. If you want to go in that path, use
a timer.
What I would suggest is to use "Recovery" options in Service Properties
dialog box. It's designed for this purpose, but I have not been able to make
it work on my .net
service. Looks like the service has to return a specific error code so the
SCM can detect it as a failed service.

"Alan Pretre" wrote:
Yes in this case however I know that SQL Server is installed on this test
machine.

In the general case though this is why I was thinking of putting my startup
access in a retry loop. It seems like this would work for a local or remote
SQL Server. I was looking for more input from others....

-- Alan
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Using dependencies may work in a situation where SQL server and your

service
are on the same machine. But what about a distributed environment where

SQL
server is on a separate server?

"Yoshi" wrote:
I would try Richard's solution before doing anything else.

This looks like it will work.

Nice Richard!
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
> Hi,
>
> You can set the dependency in code. The code snippet below is from a
> service that I wrote that assures that SQL Server is running before it
> starts. After I run InstallUtil on my service MSSQLSERVER is listed in > the
> depended on tab in the services window. When I reboot or start from a
> command line I have no problems. You should not have to code any retry > loops
> or take any special action in your code:
>
> private void InitializeComponent()
> {
> ....
> //
> // service
> //
> this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
> this.service.DisplayName = "Xxxxx";
> this.service.ServiceName = "Xxxxx";
> this.service.StartType =
> System.ServiceProcess.ServiceStartMode.Automatic;
> ....
> }
>
> --Richard
>
> "Alan Pretre" wrote:
>
>> I have a Windows service that is having trouble starting up at boot time. >> It requires SQL Server to start up. I have added MSSQLSERVER to the
>> service
>> dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't >> help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which >> made no difference. I log exceptions to the eventlog which tell me the >> following error, abridged:
>>
>> Login failed for user 'xxxxxx'.
>> at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
>> isInTransaction)
>> at
>> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec >> tionString options, Boolean& isInTransaction)
>> at System.Data.SqlClient.SqlConnection.Open()
>> <snip>
>>
>> I'm thinking I need to catch this exception in a loop a few times at
>> service
>> startup for a long enough time for SQL Server to completely spin up.
>> Anybody else have other ideas? The service is written in C#.
>>
>> -- Alan
>>
>>
>>
>>


Nov 16 '05 #7
I talked to Microsoft technical support and apparently, it's not a good idea
to use "Service Recovery" feature of Windows 2000/XP. Here is what I did
after getting ideas from them:
- In OnStart event, create a new thread to initialize the service. This way
the "Service Start" will be successful.
- If it fails (for example, because SQL server is not ready yet), use
Thread.Sleep to wait for some time and then try to initialize the service
again.
- You can choose the number of retries and delay between each.
- You have the option to stop your service after certain number of retries.
- You may want to log each retry in the event log, along with how many times
you will retry, and delay between each retry.

"Mike Mazar" wrote:
Running a loop will consume too much CPU. If you want to go in that path, use
a timer.
What I would suggest is to use "Recovery" options in Service Properties
dialog box. It's designed for this purpose, but I have not been able to make
it work on my .net
service. Looks like the service has to return a specific error code so the
SCM can detect it as a failed service.

"Alan Pretre" wrote:
Yes in this case however I know that SQL Server is installed on this test
machine.

In the general case though this is why I was thinking of putting my startup
access in a retry loop. It seems like this would work for a local or remote
SQL Server. I was looking for more input from others....

-- Alan
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Using dependencies may work in a situation where SQL server and your

service
are on the same machine. But what about a distributed environment where

SQL
server is on a separate server?

"Yoshi" wrote:

> I would try Richard's solution before doing anything else.
>
> This looks like it will work.
>
> Nice Richard!
>
>
> "Richard" <Ri*****@discussions.microsoft.com> wrote in message
> news:49**********************************@microsof t.com...
> > Hi,
> >
> > You can set the dependency in code. The code snippet below is from a
> > service that I wrote that assures that SQL Server is running before it
> > starts. After I run InstallUtil on my service MSSQLSERVER is listed

in
> > the
> > depended on tab in the services window. When I reboot or start from a
> > command line I have no problems. You should not have to code any

retry
> > loops
> > or take any special action in your code:
> >
> > private void InitializeComponent()
> > {
> > ....
> > //
> > // service
> > //
> > this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
> > this.service.DisplayName = "Xxxxx";
> > this.service.ServiceName = "Xxxxx";
> > this.service.StartType =
> > System.ServiceProcess.ServiceStartMode.Automatic;
> > ....
> > }
> >
> > --Richard
> >
> > "Alan Pretre" wrote:
> >
> >> I have a Windows service that is having trouble starting up at boot

time.
> >> It requires SQL Server to start up. I have added MSSQLSERVER to the
> >> service
> >> dependencies (as explained in http://tinyurl.com/5s7kx) but that

doesn't
> >> help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT

which
> >> made no difference. I log exceptions to the eventlog which tell me

the
> >> following error, abridged:
> >>
> >> Login failed for user 'xxxxxx'.
> >> at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> >> isInTransaction)
> >> at
> >>

System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> >> tionString options, Boolean& isInTransaction)
> >> at System.Data.SqlClient.SqlConnection.Open()
> >> <snip>
> >>
> >> I'm thinking I need to catch this exception in a loop a few times at
> >> service
> >> startup for a long enough time for SQL Server to completely spin up.
> >> Anybody else have other ideas? The service is written in C#.
> >>
> >> -- Alan
> >>
> >>
> >>
> >>
>
>
>


Nov 16 '05 #8
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
I talked to Microsoft technical support and apparently, it's not a good idea to use "Service Recovery" feature of Windows 2000/XP. Here is what I did
after getting ideas from them:
- In OnStart event, create a new thread to initialize the service. This way the "Service Start" will be successful.
- If it fails (for example, because SQL server is not ready yet), use
Thread.Sleep to wait for some time and then try to initialize the service
again.
- You can choose the number of retries and delay between each.
- You have the option to stop your service after certain number of retries. - You may want to log each retry in the event log, along with how many times you will retry, and delay between each retry.

"Mike Mazar" wrote:
Running a loop will consume too much CPU. If you want to go in that path, use a timer.
What I would suggest is to use "Recovery" options in Service Properties
dialog box. It's designed for this purpose, but I have not been able to make it work on my .net
service. Looks like the service has to return a specific error code so the SCM can detect it as a failed service.

"Alan Pretre" wrote:
Yes in this case however I know that SQL Server is installed on this test machine.

In the general case though this is why I was thinking of putting my startup access in a retry loop. It seems like this would work for a local or remote SQL Server. I was looking for more input from others....

-- Alan
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
> Using dependencies may work in a situation where SQL server and your
service
> are on the same machine. But what about a distributed environment where SQL
> server is on a separate server?
>
> "Yoshi" wrote:
>
> > I would try Richard's solution before doing anything else.
> >
> > This looks like it will work.
> >
> > Nice Richard!
> >
> >
> > "Richard" <Ri*****@discussions.microsoft.com> wrote in message
> > news:49**********************************@microsof t.com...
> > > Hi,
> > >
> > > You can set the dependency in code. The code snippet below is from a > > > service that I wrote that assures that SQL Server is running before it > > > starts. After I run InstallUtil on my service MSSQLSERVER is listed in
> > > the
> > > depended on tab in the services window. When I reboot or start from a > > > command line I have no problems. You should not have to code any retry
> > > loops
> > > or take any special action in your code:
> > >
> > > private void InitializeComponent()
> > > {
> > > ....
> > > //
> > > // service
> > > //
> > > this.service.ServicesDependedOn = new string[] {"MSSQLSERVER"};
> > > this.service.DisplayName = "Xxxxx";
> > > this.service.ServiceName = "Xxxxx";
> > > this.service.StartType =
> > > System.ServiceProcess.ServiceStartMode.Automatic;
> > > ....
> > > }
> > >
> > > --Richard
> > >
> > > "Alan Pretre" wrote:
> > >
> > >> I have a Windows service that is having trouble starting up at boot time.
> > >> It requires SQL Server to start up. I have added MSSQLSERVER to the > > >> service
> > >> dependencies (as explained in http://tinyurl.com/5s7kx) but that doesn't
> > >> help. I changed the dependency from MSSQLSERVER to SQLSERVERAGENT which
> > >> made no difference. I log exceptions to the eventlog which tell me the
> > >> following error, abridged:
> > >>
> > >> Login failed for user 'xxxxxx'.
> > >> at System.Data.SqlClient.ConnectionPool.GetConnection (Boolean& > > >> isInTransaction)
> > >> at
> > >>
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec > > >> tionString options, Boolean& isInTransaction)
> > >> at System.Data.SqlClient.SqlConnection.Open()
> > >> <snip>
> > >>
> > >> I'm thinking I need to catch this exception in a loop a few times at > > >> service
> > >> startup for a long enough time for SQL Server to completely spin up. > > >> Anybody else have other ideas? The service is written in C#.
> > >>
> > >> -- Alan
> > >>
> > >>
> > >>
> > >>
> >
> >
> >
Thanks for the follow up.


-- Alan

Nov 16 '05 #9
"Mike Mazar" <Mi*******@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
I talked to Microsoft technical support and apparently, it's not a good idea to use "Service Recovery" feature of Windows 2000/XP. Here is what I did
after getting ideas from them:
- In OnStart event, create a new thread to initialize the service. This way the "Service Start" will be successful.
- If it fails (for example, because SQL server is not ready yet), use
Thread.Sleep to wait for some time and then try to initialize the service
again.
- You can choose the number of retries and delay between each.
- You have the option to stop your service after certain number of retries. - You may want to log each retry in the event log, along with how many times you will retry, and delay between each retry.


Thanks for the followup.

-- Alan
Nov 16 '05 #10

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

Similar topics

3
by: Stanley J, Mroczek | last post by:
My disk was replaced and i reload all my software. I think that i named my computer best-si-01 instead of BEST-SI-01 and thats my error? Login failed for user 'NT AUTHORITY\NETWORK SERVICE'....
9
by: Alan Pretre | last post by:
I have a Windows service that is having trouble starting up at boot time. It requires SQL Server to start up. I have added MSSQLSERVER to the service dependencies (as explained in...
3
by: Bryan | last post by:
We created a Windows Service with C#. The service will start OK on computers that are a member of a domain, but when we try to start it on a server that is configured for a workgroup we get the...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
10
by: amirmira | last post by:
I have a Windows Service developed in VB.NET that attempts to connect to a database as soon as the service starts. I have no problem when I start the service manually - but when I restart the...
3
by: Derek Hart | last post by:
As a newbie to Windows Service programming in VB.Net, I need some clarification. I am writing a Windows Service that works with SQL Server. It works fine as a console application, but when I run it...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
0
by: Russ | last post by:
I have a Web Service that was originally created with .NET VC 2003, and subsequently converted to the 2005 version. It works fine when built as a debug version, and run on the workstation it was...
3
by: Russ | last post by:
I have a Web Service that was originally created with .NET VC 2003, and subsequently converted to the 2005 version. It works fine when built as a debug version, and run on the workstation it was...
5
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
Hi All, I am using asp.net session state service to store session. The concurrent online user will be almost 2000. Could asp.net session state service afford this? Is there any limitation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.