0

My auto-starting Windows Service written in C# depends on MS SQL Server and uses Integrated Security=SSPI

In the Installer I'm stating

this.serviceInstaller.ServicesDependedOn = new string[] {"MSSQLSERVER"};

Unfortunately, during auto-startup my service throws the exception:

System.Data.SqlClient.SqlException (0x80131904): Cannot open database "*" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'.

if I however start it manually later, it works correctly - connects to the database and works on it.

Why is that happening?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
migajek
  • 8,524
  • 15
  • 77
  • 116

1 Answers1

1

I've found out that the real issue is not about user logon, it's about MS SQL Server not being really ready as soon as the service is ready. See Connecting to SQL Server fails in autostart service, works when starting manually. SQL Server not ready, yet service is started

Community
  • 1
  • 1
migajek
  • 8,524
  • 15
  • 77
  • 116