I can't get rid of this error. I have added the "NT AUTHORITY\NETWORK" user via SSMS, along with the relevant roles using this thread as reference: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'
I am trying to make a db connection via a Windows Service. In debug mode the DB connection works fine. When I actually try and run the installed service is when I get this error.
Here is my connection string from the app.config:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=(LocalDb)\v11.0; database=MyDB; Integrated Security=True;" />
<remove name="SqlServer" />
<add name="SqlServer" connectionString="Data Source=(LocalDb)\v11.0; database=MyDB; Integrated Security=True;" />
<remove name="SqlServer" />
</connectionStrings>
I also tried with adding User ID=myDomain\myUsername; to the connection string, but that didn't help.
First read this description of the security limitations of using LocalDB. Reading that make me think that it may not be possible to use "NT AUTHORITY\NETWORK SERVICE"; I'm not sure. I think you'll need to use your credentials.
Not to be too obvious, but if you are using Integrated authentication the credentials that the service is running under must match credentials that have access to the database. If you don't want to use credentials for the service (that is, you want it to run under "NT AUTHORITY\NETWORK SERVICE"), then you'll need to add :"NT AUTHORITY\NETWORK SERVICE" as a user with adequate access to the database MyDB.
If possible, start with setting that user to db_owner for MyDB. If that works, then start adjusting permissions in SSMS to lower levels. If that doesn't work then something else is wrong with the database configuration. Ensure also that the user "NT AUTHORITY\NETWORK SERVICE" has file system access to the files that MyDB is using.
Also, you have an extra <remove name="SqlServer" /> at the end there...not sure if that's deliberate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With