<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The other blog of Miguel Pereira &#187; sql2005</title>
	<atom:link href="http://www.myrotarycar.com/blog/index.php/tag/sql2005/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myrotarycar.com/blog</link>
	<description>The BLOG where technology, music, science &#38; irrelevance all meet and melt</description>
	<lastBuildDate>Mon, 02 Aug 2010 16:56:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SQL: Killing those pesky connections</title>
		<link>http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/</link>
		<comments>http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 17:48:14 +0000</pubDate>
		<dc:creator>Miguel Pereira</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sql2000]]></category>
		<category><![CDATA[sql2005]]></category>

		<guid isPermaLink="false">http://www.myrotarycar.com/blog/?p=21</guid>
		<description><![CDATA[A while back, I wrote an article for SQL Server Central, describing a neat way for Microsoft SQL DBA's to clear out connections / SPIDs to a database without breaking much of a sweat. Although I love SSC, I just can't get past the fact that they require a visitor to register in order to view full articles. So, here it is, a reproduction of the DB script and a rather good explanation on how to use it or apply it. This goes out to all my fellow MSSQL DBAs in peril out there. [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_44" class="wp-caption alignleft" style="width: 124px"><img class="size-full wp-image-44" title="Microsoft SQL" src="http://www.myrotarycar.com/blog/wp-content/uploads/2009/01/sql.jpg" alt="Microsoft SQL" width="114" height="56" /><p class="wp-caption-text">Microsoft SQL</p></div>
<p>A while back, I wrote an article for SQL Server Central, describing a neat way for Microsoft SQL DBA&#8217;s to clear out connections / SPIDs to a database without breaking much of a sweat. Although I love SSC, I just can&#8217;t get past the fact that they require a visitor to register in order to view full articles. So, here it is, a reproduction of the DB script and a rather good explanation on how to use it or apply it. This goes out to all my fellow MSSQL DBAs in peril out there.</p>
<p>This script opens a little cursor that will clean out connections to any DBs you specify. It will release SPIDs that are active on a DB or which are locking a related SPID. I found the base script some time ago -I wish I remembered the author or location- but I&#8217;ve modified it ever so slightly to provide for a good package that can be used prior to starting a DB restore for example.<span id="more-21"></span></p>
<p>Feel free to play with it and adapt it to whatever needs you may have. I&#8217;ve used this, at times, to kill SPIDs which were causing blocking conditions. You should be able to easily modify it to go after very specific conditions. You can also packaga this up into a nice stored procedure and be able to call it programmatically in times of need.</p>
<blockquote><p>DECLARE @dbspid as int<br />
DECLARE @dbname as varchar(50)<br />
DECLARE @killcommand as varchar(50)</p>
<p>&#8211;SET @dbname = &#8216;db1&#8242;</p>
<p>DECLARE ConnectionKiller CURSOR FOR<br />
SELECT sysproc.spid FROM sysprocesses AS sysproc<br />
INNER JOIN sysdatabases AS sysdb ON<br />
sysdb.dbid = sysproc.dbid<br />
WHERE sysdb.NAME IN (@dbname)<br />
AND sysproc.spid &lt;&gt; 0<br />
UNION<br />
SELECT sysproc.blocked FROM sysprocesses AS sysproc<br />
INNER JOIN sysdatabases AS sysdb ON<br />
sysdb.dbid = sysproc.dbid<br />
WHERE sysdb.NAME IN (@dbname)<br />
AND sysproc.blocked&lt;&gt;0</p>
<p>OPEN ConnectionKiller</p>
<p>FETCH NEXT FROM ConnectionKiller INTO @dbspid<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
SET @killcommand = &#8216;KILL &#8216;+CAST(@dbspid AS VARCHAR(50))<br />
EXEC (@killcommand)<br />
FETCH NEXT FROM ConnectionKiller INTO @dbspid<br />
END<br />
CLOSE ConnectionKiller<br />
DEALLOCATE ConnectionKiller</p></blockquote>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/" target="_blank"><img src="http://www.myrotarycar.com/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/" target="_blank" title="Share on Facebook">Share on Facebook</a></p><p>
				<table cellspacing="0" cellpadding="0" border="0" style="width: 300px; height: 50px; text-align: left; margin-left: auto; margin-right: auto;">
				<tbody>
				<tr>
				<td style="text-align: center;">
				<a href="http://del.icio.us/post?url=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/&title=SQL: Killing those pesky connections" rel="nofollow">
				<img src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/delicious.png" alt="Add to Del.cio.us" style="border: 0px solid ; width: 48px; height: 48px;"/>
				</a>
				</td>
				<td style="text-align: center;">
				<a href="http://www.myrotarycar.com/blog/index.php/feed/rss/" rel="nofollow">
				<img src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/feeds.png" alt="RSS Feed" style="border: 0px solid ; width: 48px; height: 48px;"/>
				</a>
				</td>
				<td style="text-align: center;">
				<a href="http://technorati.com/faves?add=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/" rel="nofollow">
				<img src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/technorati.png" alt="Add to Technorati Favorites" style="border: 0px solid ; width: 48px; height: 48px;"/>
				</a>
				</td>
				<td style="text-align: center;">
				<a href="http://www.stumbleupon.com/submit?url=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/&title=SQL: Killing those pesky connections" rel="nofollow">
				<img src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/stumble.png" alt="Stumble It!" style="border: 0px solid ; width: 48px; height: 48px;"/>
				</a>
				
				</td>
				<td style="text-align: center;">
				<a href="http://digg.com/submit?phase=2&url=http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/" rel="nofollow">
				<img src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/digg.png" alt="Digg It!" style="border: 0px solid ; width: 48px; height: 48px;"/>
				</a>
				
				</td>
				</tr>
				<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td style="text-align: right;" ><a href="http://www.sajithmr.com"><img style="border:none" src="http://www.myrotarycar.com/blog/wp-content/plugins/addtothis/sajithmr.png"  title="Powered By Sajithmr.com" alt="www.sajithmr.com"/></a></td></tr>
				</tbody>
				</table>

                
		
				</p>]]></content:encoded>
			<wfw:commentRss>http://www.myrotarycar.com/blog/index.php/2009/01/18/sql-killing-those-pesky-connections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
