Question

I am trying to connect to a local SQL Server Express database and I got it working inside a console application but now when I try to do it for a Windows service it doesn't work. I don't know what the problem is. The connection string that worked on the console application is below:

string connectionString = @"Data Source=BEN-PC\SQLEXPRESS;Initial Catalog=testDatabase;Integrated Security=True";

Any help is really appreciated, thanks!

Était-ce utile?

La solution 2

You're using integrated security so the account that is running windows service is probably not configured on SQL Server. Windows service accounts typically have very little permissions.

You should either:

  1. Change the account for the windows service that has access to SQL Server.
  2. Or specify username and password in your connection string.

Autres conseils

Looks like you Windows Service is running under account that doesn't have permissions on the database engine.

another possible issue Datasource. It should be Data Source (with whitespace)

Most likely, the service account under which the service is running doesn't have appropriate permissions on the SQL Server Express database file or it doesn't have appropriate directory permissions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top