<?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>FailBoy &#187; .Net Framework</title>
	<atom:link href="http://www.failboy.net/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.failboy.net</link>
	<description>We reserve the right FAIL</description>
	<lastBuildDate>Thu, 26 Nov 2009 06:29:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SqlParameter is already contained by another SqlParameterCollection</title>
		<link>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/</link>
		<comments>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:00:50 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SqlParameter]]></category>
		<category><![CDATA[SqlParameterCollection]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=15</guid>
		<description><![CDATA[I discovered an interesting bug today. While executing some SQL Stored Procedures via C# I was trying to reuse a SqlParameter. However, when the SqlParameter was added to a second SqlCommand, it would throw an error when trying to execute the second command. The error encountered was the &#8220;SqlParameter is already contained by another SqlParameterCollection&#8220;. [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered an interesting bug today. While executing some SQL Stored Procedures via C# I was trying to reuse a SqlParameter. However, when the SqlParameter was added to a second SqlCommand, it would throw an error when trying to execute the second command. The error encountered was the &#8220;<em><strong>SqlParameter is already contained by another SqlParameterCollection</strong></em>&#8220;.</p>
<p>It seems that .Net&#8217;s garbage collection retains a reference to the SqlParameter used in the first SqlCommand. This reference seems to survive the closing and even disposing of the connection in use. As long as the SqlCommand object is in use, .Net seems to remember that it has already been used. To bypass this, simply call the <em><strong>sqlCommand.Parameters.Clear()</strong> </em>method. You&#8217;ll need to readd the SqlParameter or SqlParameter[] to the SqlCommand and it&#8217;ll work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
