{"id":295,"date":"2013-06-12T20:49:00","date_gmt":"2013-06-12T20:49:00","guid":{"rendered":"http:\/\/28@jodohost.com\/\/blog\/"},"modified":"2013-06-12T20:49:00","modified_gmt":"2013-06-12T20:49:00","slug":"how-to-kill-database-connections","status":"publish","type":"post","link":"http:\/\/www.jodohost.com\/blog\/index.php\/2013\/06\/12\/how-to-kill-database-connections\/","title":{"rendered":"How to kill Database Connections"},"content":{"rendered":"<p>If you see your database is making too many connections, then use the query below to kill all connections in one go.<\/p>\n<p>=============<\/p>\n<p>USE master<br \/> GO<br \/> DECLARE @dbname varchar(30), @spid varchar(10), @start datetime<br \/> SELECT @start = current_timestamp, @dbname = &#8216;airtel_sms&#8217;<\/p>\n<p>&#8212; Timeout after 5 mts<br \/> while(exists(Select * FROM sysprocesses WHERE dbid = db_id(@dbname)) AND<br \/> datediff(mi, @start, current_timestamp) < 5)<br \/> begin<br \/> DECLARE spids CURSOR FOR<br \/> SELECT convert(varchar, spid) FROM sysprocesses<br \/> WHERE dbid = db_id(@dbname)<br \/> OPEN spids<br \/> while(1=1)<br \/> BEGIN<br \/> FETCH spids INTO @spid<br \/> IF @@fetch_status < 0 BREAK<br \/> exec(&#8216;kill &#8216; + @spid)<br \/> END<br \/> DEALLOCATE spids<br \/> END<\/p>\n<p> ]]><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you see your database is making too many connections, then use the query below to kill all connections in one go. ============= USE master GO DECLARE @dbname varchar(30), @spid varchar(10), @start datetime SELECT @start = current_timestamp, @dbname = &#8216;airtel_sms&#8217; &#8212; Timeout after 5 mts while(exists(Select * FROM sysprocesses WHERE dbid = db_id(@dbname)) AND datediff(mi, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/295"}],"collection":[{"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":0,"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jodohost.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}