-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Stored Proc RAISERROR Exception Not Always Raised
PostPosted: Mon Oct 22, 2007 1:20 pm 
Newbie

Joined: Wed Jun 29, 2005 9:09 pm
Posts: 1
In debugging a related problem I discovered the following scenario where a RAISERROR executed in an MS SQL 2005 stored proc did not result in an exception in my calling code. Whether the exception is raised or not depends on whether the stored proc returns a result set. In the stored proc code below an exception is never raised in the calling code. If the line 'SELECT @TestValue AS TestValue' is commented out then an exception occurs in the calling code.

The minimum stored proc code, htm.xml, and calling code to reproduce the problem with nhibernate version 1.2.0.4 looks like

dbo.procRaiseErrorTest
===============
DECLARE @TestValue INT
DECLARE @LocalError INT
DECLARE @ErrorMessage VARCHAR( 1024 )

SELECT @TestValue = 1

SELECT @TestValue AS TestValue

SELECT @LocalError = -1

IF( 0 <> @LocalError )
BEGIN
SELECT @ErrorMessage = 'Error'
RAISERROR( @ErrorMessage, 16, 1 )
END

hbm.xml
======
<sql-query name="RaiseErrorTest">
<return-scalar column="TestValue" type="Int32"/>
EXEC dbo.procRaiseErrorTest
</sql-query>


Calling code
========
public class RaiseErrorTest
{
private int m_TestValue;
public int TestValue
{
get
{
return m_TestValue;
}
set
{
m_TestValue = value;
}
}
}

try
{
ISession Session = NHibernateHelper.GetCurrentSession( );
ITransaction TX = Session.BeginTransaction( );

IQuery Query = Session.GetNamedQuery( "RaiseErrorTest" )
.SetResultTransformer( new NHibernate.Transform.AliasToBeanResultTransformer( typeof ( RaiseErrorTest ) ) );
List<RaiseErrorTest> list = ( List<RaiseErrorTest> ) Query.List<RaiseErrorTest>( );
TX.Commit( );
Session.Close( );
}
catch ( Exception _Exception )
{
throw _Exception;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.