473,386 Members | 1,609 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,386 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

Jul 21 '05 #1
9 8128
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

Jul 21 '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

Jul 21 '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

Jul 21 '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


Jul 21 '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
>
>
>
>


Jul 21 '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
>>
>>
>>
>>


Jul 21 '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
> >>
> >>
> >>
> >>
>
>
>


Jul 21 '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

Jul 21 '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
Jul 21 '05 #10

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

Similar topics

4
by: Scott | last post by:
I think I have confused myself with reading all the articles on XML so I am hoping someone can point me in the direction for each piece of the project I am trying to develop. 1st Step - I need...
1
by: Marco Liedekerken | last post by:
Hi, When I try to stop my C# Windows Service I get the message "Couldn't perform the requested operation for service ....". Other posts suggest that it has something todo with the config file...
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...
2
by: Iwan Petrow | last post by:
Hi, I have a column DateTime in a table in MS SQL Server database. I take this column using a Web Service and show it in a TextBox in a Web Application. I want the format of the date to be...
5
by: Iwan Petrow | last post by:
Hi, I have Win application -> Web service -> Sql Server. The user input date and time in format dd/MM/yy hh:mm. I convert it to datetime and send it to a web service which save it to the db. But...
5
by: ayaz.usman | last post by:
Hi, I've built a web services proxy server, in C# using wsdl.exe, by importing wsdl. Howeever, when I go to : http://localhost/sample.asmx?wsdl, they wsdl there does not match the wsdl I fed...
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: 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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.