Restore the database to see the "no exclusive access" solution (killing the database connection Stored Procedure sqlserver), stored procedure sqlserver
The stored procedure for creating a master database is as follows:
Createproc killspid (@ dbnamevarchar (20 ))
As
Begin
Declare @ sqlnvarchar (500)
Declare @ spidint
Set @ SQL = 'maid where dbid in (select dbid from sysdatabases where name = '+ @ dbname + ')'
Exec (@ SQL)
Open getspid
Fetch next from getspid into @ spid
While @ fetch_status <>-1
Begin
Exec ('Kill '+ @ spid)
Fetch next from getspid into @ spid
End
Close getspid
Deallocate getspid
End
-- Usage
Use master
Exec killspid '''database name '''
Single quotation mark nesting
Use three single quotes. The outermost single quotes indicate vchar. The second single quotes are escaped, and the innermost single quotes are single quotes in the string. declare @ dbname nvarchar (500)
Set @ dbname = '''zcc''' -- the obtained variable is 'zcc', and set @ dbname = 'zcc' -- the obtained variable is zcc.
When restoring the database, the system prompts: Because the database is in use, it cannot obtain exclusive access to the database.
It indicates that the service is being used. The service running is disabled. When writing the service, only the editing interface is opened.
Use SQL Server2000 to restore the database, prompting that the database is in use and does not have exclusive access to the database. The database cannot be offline.
Try separating the database.