In a Java-application I am working on, I have an updater, which updates the db structure whenever a new version is started for the first time.
This updater is executed in single user mode, to ensure no one is working on the db in the meantime.
During this update, I have to request meta data and this request sometimes leads to the Error 924.
This bug occurs only since I upgraded the mssql-jdbc driver to 6.3.3 or later and I therefor opened an issue on theirGithub page.
However, during the discussion in this issue, it turned out, that neither the driver nor our code opens a new connection. Even the SQL Server Profiler logs only one connection.
During my research, I found
an article, which states, that SINGLE_USER can only be used if AUTO_UPDATE_ASYNC is turned OFF. That's the case in my database, but since async jobs on the SQL Server seem to cause problems with single user mode, my guess is, that some statements used by
the driver to load the meta data (starting with Line
988) are executed asynchronously. This presumption is reinforced by the fact, that the error only occurs, if the database is stored on a HDD drive. On SSD drives everything works fine, which sounds like some kind of race condition.
Our current workaround for this is to catch this error and retry the statement after 3 seconds, until it works. Usually it takes about 5 retries or 15 seconds.
Is there some setting in the SQL Server I am missing or what else could cause this issue?