Reputation: 393
I am trying to connect my window service to my local db. In my OnStart() method inside Service.cs class, i am getting this error..
The underlying provider failed on Open.System.Data.SqlClient.SqlException
(0x80131904): Cannot open database "EduFameProjectDB18" requested by the login.
The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.
Upvotes: 0
Views: 2507
Reputation: 27
Upvotes: 1
Reputation: 1438
You are trying to use the SYSTEM account in order to access your database. This is due to the fact that you are using integrated authentication in SQL Server and running the Windows Service under the SYSTEM account.
In order to solve this you have to provide a different credential on you windows service in order for it to open the connection properly. Make sure that the same windows user is present in the logins of SQL Server for your DB, and that it has sufficient rights to access your tables.
As an alternative you can use sql authentication, by creating a SQL Login and providing the credentials in your connection string.
Upvotes: 2