0

The facts:

  • If I use a normal domain user XYZ, to "log on as" the service all works fine, which implies the database exists and the connection string is good.
  • If I use Local Service, I get Error 18456, State 38
  • I have created <DOMAIN>\<Machine>$ login account
  • I have given the same permissions to <DOMAIN>\<MACHINE>$ as XYZ, including user mapping to the DB, server roles, securables, and status

My connection string is:

"SERVER=localhost;DATABASE=<TARGET_DATABASE>;TRUSTED_CONNECTION=True;Persist Security Info=False;"

The error message says:

Login failed for user '<DOMAIN>\<MACHINE>$'. Reason: Failed to open the explicitly specified database '<TARGET_DATABASE>'. [CLIENT: <local machine>]

Note: in above: [CLIENT: <local machine>] is the actual text, not substituted.

Other Considerations

This comes from a website that is being installed via a WIX setup program. The setup installs the service and I can select what account to use, currently it is using "Local System", but if that is bad practice we can change it, but it looks like every other service (other than the SQL ones) are using that same pattern.

  • You added the login but it seems you forgot to add the user to the database, hence the cannot open requested database message. – Dan Guzman Apr 27 '21 at 16:46
  • @DanGuzman no, the user is attached to the database. It appears right above the one that can connect in the Security/Users list – Lvl15TechNinja Apr 27 '21 at 16:54
  • A missing user is a common cause of the "Failed to open the explicitly specified database" message. Another cause is a typo of the db name in the connection string. – Dan Guzman Apr 27 '21 at 16:58
  • @DanGuzman Thanks. The dbname in the connection string does not change between a user who can log in, and the system account who cannot, so the dbname cannot be the culprit. Also, the local system user \$ exists as a logon, and as a user on the DB. – Lvl15TechNinja Apr 27 '21 at 17:02

0 Answers0