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.
This works fine but the issue is database file can not be read by the Windows service, throwing the exception "Cannot open user default database. Login failed.Login failed for user 'NT AUTHORITY\SYSTEM' " when i am trying to read the database.
If I start the computer & login then it can not read the database, but if i have start the computer & wait for a few seconds and then log into the window service it reads the database.
The account NT AUTHORITY\System which is a Local System account.. It is a powerful account that has unrestricted access to all local system resources. It is a member of the Windows Administrators group on the local computer, and is therefore a member of the SQL Server sysadmin fixed server role.
A predefined local account that is used to start a service and provide the security context for that service. The name of the account is NT AUTHORITY\System. This account does not have a password, and any password information that you supply is ignored.
When the OS can't validate who you are, you are NT AUTHORITY\ANONYMOUS LOGON. You typically see this in double hop situations like when you have a client connecting to SSRS and SSRS isn't on the same server as the SQL Server where the DB is located.
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
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