Eiliya Mohebi
Eiliya Mohebi

Reputation: 13

Window Service In C# - The underlying provider failed on Open

Hi guys i have written a windows service in c# in order to connect to database in every 10 minutes with entityframework it works fine in debug mode but when i release and install it on Local System Account it throws an exception:

The underlying provider failed on Open. Cannot open database "HCClient" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'.

my connectionstring:

add name="MyDataBaseName" connectionString="metadata=res:///Model.LocalModel.csdl|res:///Model.LocalModel.ssdl|res://*/Model.LocalModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=HCClient;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"

And when i want to start service on Local Service or Network Service it returns me Error 5: Access is Denied although i have gave one of these permission to my executable service exe i have read all topic related to my error but none of them work

any help would be appreciated

Upvotes: 0

Views: 2040

Answers (1)

logix
logix

Reputation: 642

Your service is running as the System user which doesn't (and shouldn't) have permission to log on to the database.

Either create a SQL login and add its credentials to the connection string or run your service as a user that has permissions to log in to the database.

In the service properties -> Log On tab, change the account: enter image description here

Upvotes: 1

Related Questions