Resolution
Make the database login that Octopus Server uses a member of the db_owner role on the Octopus database, then start the service. For Windows authentication that login is the service's Log On account. For SQL authentication it is the SQL user in the Octopus connection string.
Symptom
The Octopus Server Windows service fails to start, or stays in the Starting state, and the Octopus Server log shows a SQL login failure like this:
SQL Error 18456 - Login failed for user '<login>'.
In another variation of this issue, the service stayed Starting for a long time after a reboot while the log repeated this error until the login succeeded.
Scope: when this is the right article
Use this article when all of these apply:
- You run a self-hosted Octopus Server on Windows, backed by SQL Server (including Azure SQL or AWS RDS SQL Server).
- The Octopus Server service will not start, or keeps retrying at startup, and the server log shows a SQL login failure for the login Octopus uses.
This is probably not the right article if:
- The log shows no SQL error and the service fails with "The service did not start due to a logon failure". That points at the Windows account or its password rather than SQL permissions. Step 2 below covers the quick fix.
- The service starts and runs, but users cannot sign in with Active Directory or only get Everyone team permissions. See the companion article on Active Directory sign-in and team permission failures, listed under Related.
Cause
Octopus Server logs in to its SQL Server database when it starts, and the login it uses needs the db_owner role so that Octopus can manage the database, including making schema changes. If that login does not exist, is not a member of db_owner, or has been changed or removed, SQL Server rejects the connection and the service cannot finish starting. With Windows authentication, the login is the account the service runs as, so changing the service's Log On account to one without database access causes the same failure.
Occasionally, an upgrade is performed with an administrator account other than the one the service originally ran as. When that happens, the service's Log On account can switch to the administrator account that ran the upgrade instead of the original service account. You can see the change of user in the Octopus Server logs.
Diagnosis and fix
-
Find the database login Octopus uses.
On the Octopus Server machine, openservices.msc, right-click the Octopus Server service, choose Properties, and note the account on the Log On tab (Local System is the default). Then read the connection string: openOctopusServer.configin the Octopus home folder (C:\Octopusby default, orOctopusServer-<instance>.configfor a named instance) and read theOctopus.Storage.ExternalDatabaseConnectionStringsetting. Octopus Manager is not a reliable place to read it, because it shows only a parsed version that leaves out the SQL username and password. If the connection string contains a SQL user, that user is the database login. If it saysIntegrated Security=Truewith no user, the database login is the service's Log On account. -
Read the newest entries in the server log.
Open the current Octopus Server log (see Log files for the location and how to change log level). Look for the start-up failure: -
SQL Error 18456 - Login failed for usermeans SQL Server rejected the database login. Continue with the next step. -
"The service did not start due to a logon failure" means Windows rejected the service's Log On account, for example because the password is wrong or the account lacks the right to log on as a service. In
services.msc, correct the account or password on the Log On tab, then start the service. If it starts, you are done. If the log then shows the SQL login error, continue with the next step. -
Give the database login
db_owneron the Octopus database.
In SQL Server Management Studio or your tool of choice, find the login from the first step in the Octopus database's users. If it is missing, create the login and add it as a database user. Then make it a member of the db_owner role on the Octopus database. If the SQL server is remote and the login is a Windows account, the account must be a valid login on that SQL Server.
Verify service starts
-
If the login in the connection string is wrong, update the connection string.
If the SQL user or password in the connection string is incorrect, stop the Octopus Server service, then run the following from an administrative command prompt on the Octopus Server machine, replacingVALUEwith a corrected connection string. The user in the connection string must havedb_owneron the Octopus database.
Octopus.Server.exe service --stop
Octopus.Server.exe database --connectionString="VALUE"
For a named instance, add --instance="<instance name>" to the database command.
-
If the service account is wrong, change it and grant it database access.
If the service runs as an account that should not be used (for example, one that changed after a permissions cleanup), openservices.msc, right-click the Octopus Server service, choose Properties, and change the account on the Log On tab. With Windows authentication the new account is also the database login, so give itdb_owneron the Octopus database as in Step 3 before you start the service. -
Start the service.
Start the Octopus Server service and confirm it reaches the Running state and stays there. If it stops again, read the newest entries in the server log and repeat from Step 2.
Octopus.Server.exe service --start
Verify
- In
services.msc, the Octopus Server service shows Running and stays running after a few minutes. - The current Octopus Server log has no new
SQL Error 18456entries. - Open the Octopus web portal and sign in. A page that loads and accepts your sign-in confirms the server can read its database.
Related
-
Octopus Windows Service permissions: the full list of rights the service account needs, including
db_owneron the database. -
SQL Server Database: database requirements for Octopus Server, including which accounts need
db_owner. -
Moving the Octopus Server database: how to update the connection string with
Octopus.Server.exe database --connectionStringand the stop and start steps around it.