0
votes

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

1
How about creating a sql login and use that in the connection string?Peter Bons
You must be having Integrated security to true in connection string which is trying to use the identify of account under which the service is running. Either run the service under same account which has access to DB or use SQL Authentication in your connection string.vendettamit

1 Answers

1
votes

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