467,116 Members | 1,174 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,116 developers. It's quick & easy.

C# Windows Service Problem

I have created a Windows Service using Visual Studio .Net 2005 and C# which
executes a series of database jobs on a time basis. I am using
SqlConnections and SqlCommand objects to connect to a SQL Server database
and execute stored procedures and query text commands. I am running into
this problem on some computers after a reboot is done. I get the following
error message when the service attempts to execute a SqlCommand:

Could not create an instance of OLE DB provider 'MSDASQL'.
OLE DB error trace [Non-interface error: CoCreate of DSO for MSDASQL
returned 0x80070005].

This seems to only be an issue on reboot because I can restart the service
and everything works fine after that.

Any help is greatly appreciated!

Thanks!


Sep 10 '07 #1
  • viewed: 5572
Share:
8 Replies
Does it connect to a database on the same machine? perhaps the
database hasn't awoken yet... perhaps add a service dependency, or
just set a delay in the top of your service... if neither helps, look
for other likely services that might still be waking up - RPC perhaps
(which drives a lot of DTC).

Marc

Sep 10 '07 #2
"DF Dev" <jr***@newsgroup.nospamwrote in message
news:u5**************@TK2MSFTNGP02.phx.gbl...
Could not create an instance of OLE DB provider 'MSDASQL'.
OLE DB error trace [Non-interface error: CoCreate of DSO for MSDASQL
returned 0x80070005].

This seems to only be an issue on reboot because I can restart the service
and everything works fine after that.
Have you configured your windows service to have a dependency for the SQL
Server service? If not, your own service may be starting before the SQL
Server service, in which case it is necessarily not available yet.

To see the service dependencies for a particular service, go to the services
applet in your control panel, right-click and select properties on the
service in question, and open the Dependencies tab.

Nicolas
Sep 10 '07 #3
Yes it connects to a database on the same machine. I have already added
code to wait for SQL at the top of the service and I also have a dependency
for SQL Server. I am not checking RPC but I will look into that.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
Does it connect to a database on the same machine? perhaps the
database hasn't awoken yet... perhaps add a service dependency, or
just set a delay in the top of your service... if neither helps, look
for other likely services that might still be waking up - RPC perhaps
(which drives a lot of DTC).

Marc

Sep 10 '07 #4
Yes the SQL dependency is there.. Thanks.

"Nicolas Noakes" <an********@hotmail.comwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
"DF Dev" <jr***@newsgroup.nospamwrote in message
news:u5**************@TK2MSFTNGP02.phx.gbl...
>Could not create an instance of OLE DB provider 'MSDASQL'.
OLE DB error trace [Non-interface error: CoCreate of DSO for MSDASQL
returned 0x80070005].

This seems to only be an issue on reboot because I can restart the
service and everything works fine after that.

Have you configured your windows service to have a dependency for the SQL
Server service? If not, your own service may be starting before the SQL
Server service, in which case it is necessarily not available yet.

To see the service dependencies for a particular service, go to the
services applet in your control panel, right-click and select properties
on the service in question, and open the Dependencies tab.

Nicolas

Sep 10 '07 #5
It might getas you simply have to keep trying (with pause) until you
can connect, and not reporting success until you have succeeded, or a
certain "give up" threshhold is met. Alternatively, attempt to connect
as part of start-up, and use the service recovery options (first
failure, second failure, etc) to keep trying every minute-or-so.

Marc

Sep 10 '07 #6
The wierd thing is Marc that I have already done that. When the service
starts, it tries to connect to SQL. If it can't, it sleeps for so long then
tries again. It goes through this process of trying to connect several
times and if it can't it stops. But the service is starting right up so it
is connecting to the database just fine. But it throws the "CoCreate" error
the first time it tries to execute a command.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
It might getas you simply have to keep trying (with pause) until you
can connect, and not reporting success until you have succeeded, or a
certain "give up" threshhold is met. Alternatively, attempt to connect
as part of start-up, and use the service recovery options (first
failure, second failure, etc) to keep trying every minute-or-so.

Marc

Sep 10 '07 #7
"DF Dev" <jr***@newsgroup.nospamwrote in message
news:u6**************@TK2MSFTNGP02.phx.gbl...
The wierd thing is Marc that I have already done that. When the service
starts, it tries to connect to SQL. If it can't, it sleeps for so long
then tries again. It goes through this process of trying to connect
several times and if it can't it stops. But the service is starting right
up so it is connecting to the database just fine. But it throws the
"CoCreate" error the first time it tries to execute a command.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
>It might getas you simply have to keep trying (with pause) until you
can connect, and not reporting success until you have succeeded, or a
certain "give up" threshhold is met. Alternatively, attempt to connect
as part of start-up, and use the service recovery options (first
failure, second failure, etc) to keep trying every minute-or-so.

Marc

0x80070005 means Access Denied, that means that you are trying to
load/access the DSO provider library, but the current user has not the
appropriate privileges to do so.
Mind to post some code? Especially the connection string(s) might be
helpful. Note that connecting to SQL server and using DSO are different
things.

Willy.

Sep 10 '07 #8
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:eM*************@TK2MSFTNGP06.phx.gbl...
"DF Dev" <jr***@newsgroup.nospamwrote in message
news:u6**************@TK2MSFTNGP02.phx.gbl...
>The wierd thing is Marc that I have already done that. When the service
starts, it tries to connect to SQL. If it can't, it sleeps for so long
then tries again. It goes through this process of trying to connect
several times and if it can't it stops. But the service is starting
right up so it is connecting to the database just fine. But it throws
the "CoCreate" error the first time it tries to execute a command.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegr oups.com...
>>It might getas you simply have to keep trying (with pause) until you
can connect, and not reporting success until you have succeeded, or a
certain "give up" threshhold is met. Alternatively, attempt to connect
as part of start-up, and use the service recovery options (first
failure, second failure, etc) to keep trying every minute-or-so.

Marc


0x80070005 means Access Denied, that means that you are trying to
load/access the DSO provider library, but the current user has not the
appropriate privileges to do so.
Mind to post some code? Especially the connection string(s) might be
helpful. Note that connecting to SQL server and using DSO are different
things.

Willy.
But shouldn't it do the same thing when you restart the service manually??
It works fine when you go into Services and restart it. It just doesn't
work on boot up.

Here is some sample code:

SqlConnection CurrentConnection = new SqlConnection();
strConnectionString = @"data source=MyServer;

initial catalog=MyDatabase;

integrated security=SSPI;

persist security info=False;

Trusted_Connection=Yes";

CurrentConnection.ConnectionString = strConnectionString;

CurrentConnection.Open();

JobsCommand = new SqlCommand();

JobsCommand.CommandText = "exec sp_Test"

JobsCommand.Connection = CurrentConnection;

JobsCommand.CommandTimeout = 0;

JobsCommand.ExecuteNonQuery();
Sep 10 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Kris | last post: by
reply views Thread by Scott Davies | last post: by
10 posts views Thread by Ger | last post: by
reply views Thread by Charles Leonard | last post: by
1 post views Thread by Mahesh Devjibhai Dhola | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.