user3913452
user3913452

Reputation: 393

Cannot open database in windows service

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

Answers (2)

Tariqul Shakil
Tariqul Shakil

Reputation: 27

  1. Connect on Sql Server Management Studio.
  2. Now go Security -> NT AUTHORITY\SYSTEM Right Click -> Properties
  3. Click -> Server Roles
  4. Check public, sysadmin
  5. Click Ok

Upvotes: 1

LazyOfT
LazyOfT

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

Related Questions