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]
# 1

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

RizwanSharp at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
i thought sqlexpress only supported local connections... SERVER=N16\\SQLEXPRESS wouldn't be valid if it's not the local machine if that's the case.
JDPeckham at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3
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.
VMazur at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4

  1. SQLExpress CAN be located on a remote system BUT it's not configured to do so.
  2. Some SQLExpress instance options require the instance to be local.
  3. If you want to access any instance of SQL Server, you're going to have to make sure that the credentials you specify are known to the instance. Windows Authentication (Trusted_Connection or Integrated Security) require accounts on the server instance as well.

See Chapter 9 of my HHG 7th Edition FMI.

WilliamVaughn at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5

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.

MattNeerincx at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified