Our application has in-built functionality to update the database it uses (triggered when an app update is downloaded from our server.)
Usually, the update comprises of table and data conversion and then a drop of existing stored procedures and a create of all current stored procedures.
So we do the following from C#:
- Create Connection
- Set database to Single User Mode
- Run upgrade script to upgrade tables and convert data
- Run upgrade script to drop existing stored procedures and add new ones
- Set database to Multi User Mode
- Close connection
Step 2 -5 are done using the same connection. For some clients it occassionaly errors out in the middle of Step3 or Step 4. The log shows:
Error: Database 'MyDB' is already open and can only have one user at a time.
This is very strange because at that time we are already in Single User mode so no other user should be able to connect to the database, let alone somehow put it in Single User mode for its own connection.
We are wondering if some internal SQL Server process is taking over our Single User mode and preventing us from completing the update.
We are aware that if AUTO_UPDATE_STATISTICS_ASYNC is turned ON this may interrupt Single User Mode, but we have verified that it is turned off and it still occurred for the client.
Could a CHECKPOINT operation interrupt it? If so, what do we do about that, because that is a server-wide setting so we cannot modify it.