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!

有帮助吗?

解决方案 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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top