January 26, 2005 at 10:26 am
Hi Everyone,
I'm doing some development in VB.Net 2003 with a SQL Server 2000 backend. I would like to be able to throw a DBConcurrencyException exception from within a stored procedure in SQL Server. Does anyone know if this is possible and how I go about it? I know how to raise errors, but I can't seem to figure out how to throw a VB.Net error that VB.Net can catch in it's Catch block.
Thanks,
Wes
January 27, 2005 at 8:15 am
It is not possible to throw an Exception from within a stored procedure because SQL Server 2000 does not use and is not aware of the Microsoft.NET Framework. You will have to use RAISERROR to raise an error, which will be handled by the SqlCommand object, causing it to throw an SqlException. You can catch the SqlException.
As the SqlException could have occurred for any number of reasons, you will need to examine the error code to determine whether the SqlException was thrown due to your RAISERROR statement being executed, and if so then throw a DBConcurrencyException.
Or you could wait until SQL Server 2005 is released as you will be able to write stored procedures in managed code.
Keith
January 27, 2005 at 8:19 am
Hi Keith,
Thanks for confirming what I thought was the case. I didn't think I would be able to in SQL Server 2000 and I can't wait for 2005, so I will have to handle it the alternative way. I think I will just raise a specific error number and when I'm handling the SQLException I'll just look for that number. I'm pretty sure I can do that.
Thanks,
Wes
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply