When you execute a library script, you tend to drop the original database, and because SQL Server detects a data connection that prevents the drop database operation from being performed, the build script often fails, so we need a way to force a disconnected database. The following T-SQL implementation can be done:
Copy Code code as follows:
DECLARE @i int DECLARE cur cursor for select spid from sysprocesses where db_name (dbid) = ' your_database_name ' Open cur FET CH Next from cur to @i while @ @fetch_status =0 begin EXEC ("Kill" +@i) fetch next from cur to @i end close cur E cur
We can write this SQL into the Library batch script and put it at the beginning of the script:
Copy Code code as follows:
:: Disconnect existing Fortune database connections
Osql-s '%1 '-u '%2 '-p '%3 '-Q ' declare @i int DECLARE cur cursor for select spid from sysprocesses where db_name (dbid) = ' Yo Ur_database_name ' Open cur fetch next from cur to @i while @ @fetch_status =0 begin EXEC (' kill ' +@i) fetch the next from cur Into @i end close cur deallocate cur "