I have created a windows service & my service is dependent on the SQL server service. First, SQL started and then my service started when starting PC or restarting PC.
you can add this on Connection string
persist security info=True
Go to security tab under your database.
Under security, Click to expand the Users tab.
Find weather NT AUTHORITY\SYSTEM is present.
If not, Right click on users, Click on new user
In new user window, general tab change the user type to windows user.
Select the User name to, NT AUTHORITY\SYSTEM you will have to find it in the Advanced tab, find now, and select system.
Similarly for login name, browse and find NT AUTHORITY\SYSTEM.
And in the membership tab to the left, select all the required boxes and click ok.
Probably this would fix your issue. Hope this helps.
I bet you have this in your connection string:
Integrated Security=SSPI
or something similar.
Now the account that service is running under (NT AUTHORITY\SYSTEM) tries to connect to the database - and can't since it's not authorized to do so.
You can:
NT AUTHORITY\SYSTEM in your SQL Server and give it the necessary permissions it needs for your appOR:
you create a specific application user account in SQL Server (login to SQL Server and user in your database) and change your connection string to:
User ID=(your app account);pwd=YourPassword
I removed Trusted_Connection=yes from connection string and it worked perfectly.
I actually just changed the permissions for the NT AUTHORITY\SYSTEM user in SQL Server and this worked for me.
The simple solution is to check your web.config file and make sure one of these is part of the database connection string:
Trusted Connection=false
OR
Integrated Security=True