<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Error Handling in T-SQL</title>
	<atom:link href="http://sqlfool.com/2008/12/error-handling-in-t-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/</link>
	<description>Self-Professed SQL Scripting Junkie!</description>
	<lastBuildDate>Fri, 04 May 2012 08:30:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Rebeccah</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-6281</link>
		<dc:creator>Rebeccah</dc:creator>
		<pubDate>Thu, 23 Jun 2011 04:13:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-6281</guid>
		<description>I&#039;m trying to figure out how to catch an error and then NOT roll back the transaction, but instead simply skip inserting the erroneous record - but still notify about it.  Is this appropriate for that, or do I need to fiddle with a MaxErrors setting or some such?

Thanks,

Rebeccah</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to figure out how to catch an error and then NOT roll back the transaction, but instead simply skip inserting the erroneous record &#8211; but still notify about it.  Is this appropriate for that, or do I need to fiddle with a MaxErrors setting or some such?</p>
<p>Thanks,</p>
<p>Rebeccah</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Sachers</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-5728</link>
		<dc:creator>Martin Sachers</dc:creator>
		<pubDate>Tue, 29 Mar 2011 08:07:33 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-5728</guid>
		<description>Hi Steve,

I just found your post and implemented it. The proc where I built it in runs fine, but your error-handling ALWAYS brings up an error:

&quot;Meldung 50000, Ebene 15, Status 1, Prozedur dba_logError_sp, Zeile 152
Zeichenfolgen- oder Binärdaten würden abgeschnitten.&quot;

which means something like
&quot;Message 50000, flat 15, status 1, procedure dba_logError_sp, row 152
String or binary data would be truncated.

Then I just set the declaration of @returnError to 0 and there was no error at all. Which is not the purpose of an error-handling.
Where could I have done something wrong?

Best regards from Vienna/Austria!
Martin</description>
		<content:encoded><![CDATA[<p>Hi Steve,</p>
<p>I just found your post and implemented it. The proc where I built it in runs fine, but your error-handling ALWAYS brings up an error:</p>
<p>&#8220;Meldung 50000, Ebene 15, Status 1, Prozedur dba_logError_sp, Zeile 152<br />
Zeichenfolgen- oder Binärdaten würden abgeschnitten.&#8221;</p>
<p>which means something like<br />
&#8220;Message 50000, flat 15, status 1, procedure dba_logError_sp, row 152<br />
String or binary data would be truncated.</p>
<p>Then I just set the declaration of @returnError to 0 and there was no error at all. Which is not the purpose of an error-handling.<br />
Where could I have done something wrong?</p>
<p>Best regards from Vienna/Austria!<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Error handling in T-SQL &#171; 資訊與工作</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-5531</link>
		<dc:creator>Error handling in T-SQL &#171; 資訊與工作</dc:creator>
		<pubDate>Tue, 11 Jan 2011 06:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-5531</guid>
		<description>[...] Error Handling in T-SQL « SQL Fool Error handling is one of those things in SQL Server that just doesn&#8217;t get the attention it deserves. Even a properly constructed stored procedure can still result in error, such as primary key or unique constraint errors. [...]</description>
		<content:encoded><![CDATA[<p>[...] Error Handling in T-SQL « SQL Fool Error handling is one of those things in SQL Server that just doesn&#8217;t get the attention it deserves. Even a properly constructed stored procedure can still result in error, such as primary key or unique constraint errors. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve K.</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-5085</link>
		<dc:creator>Steve K.</dc:creator>
		<pubDate>Thu, 18 Mar 2010 16:31:28 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-5085</guid>
		<description>Hi Michelle,

This is quite a bit after your post but I ran across it.  Nice post, good information.  I was wondering if you could post or email an example of the contents of the dba_logError_sp stored procedure?

I have a good handle on catching errors in my procs but the logic that goes into logging them and what to do next is a little less clear.  It seems most of this unclearness is from what this stored proc actually does.  

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi Michelle,</p>
<p>This is quite a bit after your post but I ran across it.  Nice post, good information.  I was wondering if you could post or email an example of the contents of the dba_logError_sp stored procedure?</p>
<p>I have a good handle on catching errors in my procs but the logic that goes into logging them and what to do next is a little less clear.  It seems most of this unclearness is from what this stored proc actually does.  </p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Monitoring Process for Performance Counters : SQL Fool</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-4938</link>
		<dc:creator>Monitoring Process for Performance Counters : SQL Fool</dc:creator>
		<pubDate>Wed, 16 Sep 2009 17:22:08 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-4938</guid>
		<description>[...] Getting an error about dba_logError_sp? Take a look at my error handling proc. [...]</description>
		<content:encoded><![CDATA[<p>[...] Getting an error about dba_logError_sp? Take a look at my error handling proc. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-01-08 &#171; News to Me</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-126</link>
		<dc:creator>links for 2009-01-08 &#171; News to Me</dc:creator>
		<pubDate>Thu, 08 Jan 2009 15:01:37 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-126</guid>
		<description>[...] Error Handling in T-SQL (tags: sql howto sqlserver error) [...]</description>
		<content:encoded><![CDATA[<p>[...] Error Handling in T-SQL (tags: sql howto sqlserver error) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michelle Ufford</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-84</link>
		<dc:creator>Michelle Ufford</dc:creator>
		<pubDate>Sun, 21 Dec 2008 14:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-84</guid>
		<description>Hi Jamie,

The error proc, dba_logError_sp , will indeed return the error to the calling app if @returnError = 1, which is the default behavior.  

    /* Should we return an error message to the calling proc? */
    IF @returnError = 1
        RAISERROR
        (
              @errorReturnMessage
            , @errorReturnSeverity
            , 1
        ) WITH NOWAIT;

The reason I wrote the return section this way is that I&#039;ve used the error logging proc as a form a of debug; if a condition occurs that I want to be logged but I don&#039;t want to return an error, I set @returnError = 1 and @forceExit = 0.

To your point, you could modify the error proc to return -1 and have your application check for and handle errors based on the return value.  This just depends on your application preferences.</description>
		<content:encoded><![CDATA[<p>Hi Jamie,</p>
<p>The error proc, dba_logError_sp , will indeed return the error to the calling app if @returnError = 1, which is the default behavior.  </p>
<p>    /* Should we return an error message to the calling proc? */<br />
    IF @returnError = 1<br />
        RAISERROR<br />
        (<br />
              @errorReturnMessage<br />
            , @errorReturnSeverity<br />
            , 1<br />
        ) WITH NOWAIT;</p>
<p>The reason I wrote the return section this way is that I&#8217;ve used the error logging proc as a form a of debug; if a condition occurs that I want to be logged but I don&#8217;t want to return an error, I set @returnError = 1 and @forceExit = 0.</p>
<p>To your point, you could modify the error proc to return -1 and have your application check for and handle errors based on the return value.  This just depends on your application preferences.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Thomson</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-83</link>
		<dc:creator>Jamie Thomson</dc:creator>
		<pubDate>Sun, 21 Dec 2008 12:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-83</guid>
		<description>In the code above I think I&#039;m writing in saying that whoever called the sproc where the error occurred would never know about the error - hence they would assume that whatever activity they were doing had been committed. This strikes me as being a very bad thing.
There needs to be a way of reporting back to the caller than error occurred. Logging the error is all well and good (and very much best practice) but you MUST report back to the caller. As a rule I catch the error, log it, and then rethrow it back to the caller and have it handled at the top of the call stack - probably by reporting it back to the person that instigated the activity.

-Jamie</description>
		<content:encoded><![CDATA[<p>In the code above I think I&#8217;m writing in saying that whoever called the sproc where the error occurred would never know about the error &#8211; hence they would assume that whatever activity they were doing had been committed. This strikes me as being a very bad thing.<br />
There needs to be a way of reporting back to the caller than error occurred. Logging the error is all well and good (and very much best practice) but you MUST report back to the caller. As a rule I catch the error, log it, and then rethrow it back to the caller and have it handled at the top of the call stack &#8211; probably by reporting it back to the person that instigated the activity.</p>
<p>-Jamie</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Dyckes</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-79</link>
		<dc:creator>Stephen Dyckes</dc:creator>
		<pubDate>Fri, 19 Dec 2008 19:07:51 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-79</guid>
		<description>Thanks for a great reminder about my lack of error handling. It lays out a great method for SQL2005. Too bad I am still stuck in 2000 with most of my environmnents, but there are ways to handle it there as well.</description>
		<content:encoded><![CDATA[<p>Thanks for a great reminder about my lack of error handling. It lays out a great method for SQL2005. Too bad I am still stuck in 2000 with most of my environmnents, but there are ways to handle it there as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michelle Ufford</title>
		<link>http://sqlfool.com/2008/12/error-handling-in-t-sql/comment-page-1/#comment-75</link>
		<dc:creator>Michelle Ufford</dc:creator>
		<pubDate>Wed, 17 Dec 2008 15:17:06 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=254#comment-75</guid>
		<description>Thanks for the head&#039;s up, Rob!  I&#039;ll take a look and see if I can fix it.</description>
		<content:encoded><![CDATA[<p>Thanks for the head&#8217;s up, Rob!  I&#8217;ll take a look and see if I can fix it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

