bitwarden / server

Bitwarden infrastructure/backend (API, database, Docker, etc).
https://bitwarden.com
Other
15.66k stars 1.32k forks source link

SQL Server is in Upgrade Mode #232

Closed chrisls121 closed 6 years ago

chrisls121 commented 6 years ago

When attempting to update to version 1.17.0 I received the following error when starting Bitwarden during the upgrade process.

Unhandled Exception: System.Data.SqlClient.SqlException: Login failed for user 'sa'. Reason: Server is in script upgrade mode. Only administrator can connect at this time. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Bit.Setup.Program.MigrateDatabase() in /Users/kyle/Projects/bitwarden/core/util/Setup/Program.cs:line 246 at Bit.Setup.Program.Main(String[] args) in /Users/kyle/Projects/bitwarden/core/util/Setup/Program.cs:line 55

However, I was able to successfully upgrade by simply running the update again.

kspearrin commented 6 years ago

How did you start it during the upgrade process? Did you use the update command? It should wait 30 seconds before trying to migrate. Can you provide full output of update script?

chrisls121 commented 6 years ago

Yes, I ran the update using the update command and I did observe the script waiting 30 seconds. Perhaps it is just the speed of my VM. It is running on 2GB Digital Ocean standard droplet (Bitwarden is the only thing running on the VM)

Unfortunately, I have since closed out the terminal session so I no longer have access to the full output of the upgrade process.

kspearrin commented 6 years ago

I'll update it to add a longer sleep and a better message. If it fails, just wait a bit longer and run updatedb and it will be fine.

kspearrin commented 6 years ago

I upped it to 60 seconds for now. Hopefully that should cover most users. See https://github.com/bitwarden/core/commit/6179813c9a8aca6ee3480a3d0908030f1f926d9e

chrisls121 commented 6 years ago

Looks good, I think it took longer in this case because the MSSQL container was updated from CU2 to CU4.

Witti commented 6 years ago

60 seconds was to low for my machine, changed it to 200 and it worked.

laemm-line commented 6 years ago

I have the same problem, 60 seconds is not enough. Can you not somehow check if the DB is really up and wait longer if necessary?

Mart124 commented 6 years ago

302 will help 👍