We have an application running on SQL server. This application restores DB very frequently using Single user mode. Following are the SQLs that are executed to restore the database in single user mode and to get the database back in multi user mode.
On searching for this problem I found out that people have faced similar problem but I was unable to find out the root cause and debug steps for this problem. Stopping the SQL server is provided as a solution to kick out these background processes but this is not a feasible in our case as code to restore DB runs very frequently resulting in this problem at a good frequency.
alter database [test-db] set single_user with rollback immediate; --This sql is run using test-db use master;restore database [test-db] from database_snapshot = 'snapshot_test-db'; alter database [test-db] set multi_user;
After switching the test-db to single user mode some 4-5 background processes of Taskmanager jump in for the test-db kicking off the session that application has taken over in single user mode . These background process are deadlocked between them selves. Please refer to the output of sp_who2 below at link.
http://social.microsoft.com/Forums/getfile/200625
and following is the deadlock XML.
NOTE: SPIDs in deadlock XML may differ from the output of sp_who2 as spids keeps on changing for these processes.
<deadlock-list><deadlock victim="process4bbfc78"><process-list><process id="process4bbfc78" taskpriority="0" logused="10000" waitresource="DATABASE: 5 " waittime="705" schedulerid="1" kpid="1648" status="background" spid="22" sbid="0" ecid="0" priority="0" trancount="0"><executionStack/><inputbuf></inputbuf></process><process id="process6d44388" taskpriority="0" logused="10000" waitresource="DATABASE: 5 " waittime="419" schedulerid="1" kpid="5796" status="background" spid="30" sbid="0" ecid="0" priority="0" trancount="0"><executionStack/><inputbuf></inputbuf></process><process id="process6d44718" taskpriority="0" logused="10000" waitresource="DATABASE: 5 " waittime="109" schedulerid="1" kpid="3908" status="background" spid="16" sbid="0" ecid="0" priority="0" trancount="0"><executionStack/><inputbuf></inputbuf></process><process id="process4bbee38" taskpriority="0" logused="10000" waitresource="DATABASE: 5 " waittime="313" schedulerid="1" kpid="2656" status="background" spid="15" sbid="0" ecid="0" priority="0" trancount="0"><executionStack/><inputbuf></inputbuf></process></process-list><resource-list><databaselock subresource="FULL" dbid="5" dbname="unknown" id="lock4671600" mode="S"><owner-list><owner id="process6d44718" mode="S"/><owner id="process4bbee38" mode="S"/></owner-list><waiter-list><waiter id="process4bbfc78" mode="X" requestType="wait"/></waiter-list></databaselock><databaselock subresource="FULL" dbid="5" dbname="unknown" id="lock4671600" mode="S"><owner-list><owner id="process4bbfc78" mode="S"/></owner-list><waiter-list><waiter id="process6d44388" mode="X" requestType="wait"/></waiter-list></databaselock><databaselock subresource="FULL" dbid="5" dbname="unknown" id="lock4671600" mode="S"><owner-list><owner id="process4bbfc78" mode="S"/></owner-list><waiter-list><waiter id="process6d44718" mode="X" requestType="wait"/></waiter-list></databaselock><databaselock subresource="FULL" dbid="5" dbname="unknown" id="lock4671600" mode="S"><owner-list><owner id="process4bbfc78" mode="S"/></owner-list><waiter-list><waiter id="process4bbee38" mode="X" requestType="wait"/></waiter-list></databaselock></resource-list></deadlock></deadlock-list>
On searching for this problem I found out that people have faced similar problem but I was unable to find out the root cause and debug steps for this problem. Stopping the SQL server is provided as a solution to kick out these background processes but this is not a feasible in our case as code to restore DB runs very frequently resulting in this problem at a good frequency.
I also made sure that SQL Server Agent is not running. The SQL services running on server are SQL server, SQL Server Browser and SQL Server VSS Writer.
Any help will be appreciated as this is a blocker problem.
Thanks,