Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
anujpratap84
Starting Member
45 Posts |
Posted - 2010-08-17 : 06:28:35
|
| Hi,My query was working fine in sql 2005.But it giving error in sql 2008.Please help.Here is my query:USE MASTER;DECLARE @DatabaseName nvarchar(50), @SPId int,@sql NVARCHAR(100);SET @DatabaseName = N'AAAAScriptDB';SELECT @SPId=SPId FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId ;SET @sql='KILL '+CAST(@SPId AS varchar(5));EXEC(@sql)I execute this query from my C# application before deleting the database.Anuj Pratap Singh |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-08-17 : 06:42:27
|
| You want to maybe tell us what error it's giving?You should switch to using a combination of sys.dm_exec_sessions and sys,dm_exec_requests and filter for is_user_process = 1. System processes can be using a database and they cannot be killed.--Gail ShawSQL Server MVP |
 |
|
|
anujpratap84
Starting Member
45 Posts |
Posted - 2010-08-17 : 12:09:10
|
| Thanks for quick reply....I have used the following query ... ALTER DATABASE sDbName SET OFFLINE WITH ROLLBACK IMMEDIATE ALTER DATABASE sDbName SET ONLINE DROP Database sDbName Now its working fine.Anuj Pratap Singh |
 |
|
|
|
|
|