Last night while migrating a 2TB database we came across the same issue:
Database 'DBname' cannot be opened. It is in the middle of a restore.
Error: 927, Severity: 14, State: 2.
A system process, SPID 46, with sa login and task as DBMIRROR was "connected" to the old database that is in restoring mode. How does that happen when I put it into Single User and then did a TAIL backup of the log and put it into restoring mode? Every two minutes in the error log SPIDS 14, 15, 16, 17 alternately keep trying to open the restoring database and generating that error. The migrate strategy we used was database log shipping to the new disk and last night we brought the secondary online as primary. This database also was mirroring to a partner server, I removed that at the very beginning. These are the steps taken to migrate the database:
--ensure most recent log shipped backup was restored
--via GUI remove MIRRORING from the primary
--put in SINGLE_USER mode
--via GUI, change name of db from Primary to Primary_OLD
--take TAIL of log backup, Primary_OLD goes into restoring mode
--restore TAIL to Primary_NEW WITH RECOVERY
--via GUI, rename Primary_NEW to Primary
--put back into MULTI_USER mode
So it is now successfully working on the new disk, but we have the lingering error every two minutes as noted. We have checked all the mirroring monitors/tables and even ran ALTER DB...PARTNER OFF etc and it all states there is no mirroring configured.
This will be resolved when we decide to drop the Primary_OLD database...but it is a little bothersome seeing that connection and the open errors when they should not be happening, would be nice to know what is causing this. Thanks.