ADO in aWindows Service
I have a problem integrating an ADO connection into a Service in C#. The peculiar thing is that the same thing works well in an application but throws a problem in the Service i.e. the Service doesnt want to start...
The problem is at establishing the connection - but the same thing works just fine in an Windows application.
string
MySqlConnString ="SERVER=N16\\SQLEXPRESS; TRusted_connection=yes; database = EventTrack2007";MySqlConnection =newSqlConnection();
MySqlConnection.ConnectionString = MySqlConnString;
MySqlConnection.Open();
Thanks in advance
[837 byte] By [
costaaa] at [2007-12-28]
You may be running Windows Service under Local System account and you are using connection with SQL Server under Windows Authentication, Either try to run your service under Local User account or change Authentication Mode of the Connection.
I hope this will work.
Best Regards,
Rizwan aka RizwanSharp
Yes, it is true about local connections for the Express, but it does not mean that any user will have permissions to connect to the database. When your service is running, it is using specific login account, which could be different from the account you logged into the system, depending on how you configured it. This account has to have permissions to connect to the database and most likely it has no permissions.
I think the main problem you are hitting here is the service is slow to start and probably is killed by SCM (service control manager).
So what you want to do is avoid doing heavyweight things during startup of your service and defer these to later.
For example, one simple fix will be when the service starts, spin up a new thread to do the database work so you don't block the main service thread.