Title

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help
in Search

How To Cloase All Open Connection of Database

Last post 08-07-2008, 3:30 AM by Akshay. 0 replies.
Sort Posts: Previous Next
  •  08-07-2008, 3:30 AM 2981

    How To Cloase All Open Connection of Database

    I am Using this code to close all connection of a database. Sometimes it works and some times it raise error like "Databas eis exclussively used by some process". what should i do.

    CREATE PROCEDURE RemoveConnection
     AS
    DECLARE @SQL varchar(400)
    DECLARE @DB NVARCHAR
    set @DB=db_name()
    SET @SQL = ''

    SELECT @SQL = @SQL + 'Kill ' + Convert(varchar, SPId) + ';' FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DB) AND SPId <> @@SPId
    EXEC(@SQL)
    GO
    Please reply soon.

View as RSS news feed in XML
Copyright © 2004 - 2008 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems