﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Acessing the SQL Error code within a DAL exception</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Fri, 29 May 2026 15:44:37 GMT</lastBuildDate><ttl>20</ttl><item><title>Acessing the SQL Error code within a DAL exception</title><link>http://forum.strataframe.net/FindPost8820.aspx</link><description>Hi,&lt;/P&gt;&lt;P&gt;I want to wrap certain database processing in Try blocks, check any error and retry&amp;nbsp;(within limits) if they are expected, e.g. locking. However, I'm having trouble identifying the native SQL error code&amp;nbsp;within the Exception, e.g.&lt;/P&gt;&lt;P&gt;blTry = True&lt;BR&gt;While blTry&lt;BR&gt;&amp;nbsp;&amp;nbsp; Try&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.FillByStoredProcedure(StoredProc)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blTry = False&lt;BR&gt;&amp;nbsp;&amp;nbsp; Catch ex As Exception&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blTry = CheckTheError(ex)&lt;BR&gt;&amp;nbsp;&amp;nbsp; End Try&lt;BR&gt;End While&lt;/P&gt;&lt;P&gt;I can see the SQL Error Description but I want to evalute errors&amp;nbsp;using native SQL error codes.&lt;/P&gt;&lt;P&gt;Cheers, Peter</description><pubDate>Thu, 17 May 2007 09:13:58 GMT</pubDate><dc:creator>Peter Jones</dc:creator></item><item><title>RE: Acessing the SQL Error code within a DAL exception</title><link>http://forum.strataframe.net/FindPost8856.aspx</link><description>Glad that worked out for you :)&lt;/P&gt;&lt;P&gt;Oh, and if the type is&amp;nbsp;a DataLayerSavingException, then it will have the exceptions listed within the SavingErrors collection because there might be more than one, but that's only if you set your business object's ErrorSavingMode to ContinueOnError (non default) and wrap the bo.Save() in a try/catch.</description><pubDate>Thu, 17 May 2007 09:13:58 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Acessing the SQL Error code within a DAL exception</title><link>http://forum.strataframe.net/FindPost8848.aspx</link><description>Hi Ben,&lt;/P&gt;&lt;P&gt;Perfect - thank you.&lt;/P&gt;&lt;P&gt;Cheers, Peter</description><pubDate>Wed, 16 May 2007 17:45:59 GMT</pubDate><dc:creator>Peter Jones</dc:creator></item><item><title>RE: Acessing the SQL Error code within a DAL exception</title><link>http://forum.strataframe.net/FindPost8825.aspx</link><description>Check the type of the exception... you want the SqlException type because it has an Errors collection&amp;nbsp;in it.&amp;nbsp; You'll probably want to do something like this in your CheckTheError() method:&lt;/P&gt;&lt;P&gt;Public Shared Sub CheckTheError(ByVal ex As Exception)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Get the reference to the SqlException&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim sqlEx As SqlException&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim&amp;nbsp;checkingEx&amp;nbsp;As Exception = ex&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Cycle through the InnerExceptions and find the proper exception&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'-- Attempt to get the exception as an SqlException&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlEx = TryCast(checkingEx, SqlException)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If sqlEx IsNot Nothing Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Do '-- You have a reference to the exception&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else If checkingEx.InnerException IsNot Nothing Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkingEx = checkingEx.InnerException '-- Let it loop to test this new exception&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '--&amp;nbsp;The&amp;nbsp;testing exception&amp;nbsp;is not a SqlException and none of the InnerExceptions are either, so&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '&amp;nbsp;&amp;nbsp;log the top exception and then bail&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Loop&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Handle the sqlEx object with its Errors collection&lt;BR&gt;End Sub</description><pubDate>Wed, 16 May 2007 09:18:41 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>