<?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>jcarle.com &#187; .NET Framework</title>
	<atom:link href="http://www.jcarle.com/category/net-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jcarle.com</link>
	<description>The musings of a web developer</description>
	<lastBuildDate>Tue, 27 Apr 2010 14:19:09 +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>Extending the SqlDataAdapter with a FillTimeout</title>
		<link>http://www.jcarle.com/2009/07/21/extending-the-sqldataadapter-with-a-filltimeout/</link>
		<comments>http://www.jcarle.com/2009/07/21/extending-the-sqldataadapter-with-a-filltimeout/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 04:30:24 +0000</pubDate>
		<dc:creator>Jean-Sebastien Carle</dc:creator>
				<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">http://www.jcarle.com/?p=62</guid>
		<description><![CDATA[The SqlDataAdapter has a CommandTimeout property but does offer any method to set any kind of timeout during the Fill method. If you are returning rather large data sets, you can quickly run into a problem. The obvious solution would be to inherit the SqlDataAdapter and simply override the Fill method, except that the SqlDataAdapter [...]]]></description>
			<content:encoded><![CDATA[<p>The SqlDataAdapter has a CommandTimeout property but does offer any method to set any kind of timeout during the Fill method. If you are returning rather large data sets, you can quickly run into a problem. The obvious solution would be to inherit the SqlDataAdapter and simply override the Fill method, except that the SqlDataAdapter cannot be inherited. As a result, we must implement the same methods that the SqlDataAdapter does and attach them to a private internal SqlDataAdapter to do all the heavy lifting. With the use of anonymous delegates, we can easily rework the Fill methods to offer a new FillTimeout property and throw an exception when we exceed our desired timeout.</p>
<pre class="brush: csharp;">
public int FillTimeout
{
    get { return _fillTimeout; }
    set { _fillTimeout = value; }
}

public int Fill(DataSet dataSet)
{
    if (_fillTimeout == 0)
    {
        return _adapter.Fill(dataSet);
    }
    else
    {
        int rows = 0;
        Thread fillThread = new Thread(delegate() { rows = _adapter.Fill(dataSet); });
        fillThread.Start();
        if (fillThread.Join(_fillTimeout * 1000))
        {
            return rows;
        }
        else
        {
            try
            {
                fillThread.Abort();
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            }
            throw new TimeoutException();
        }
    }
}
</pre>
<p>Download the full ExtendedSqlDataAdapter class : <a href="http://www.jcarle.com/wp-content/uploads/2009/07/ExtendedSqlDataAdapter.cs">ExtendedSqlDataAdapter.cs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jcarle.com/2009/07/21/extending-the-sqldataadapter-with-a-filltimeout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
