Trapping a particular SQL Error Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI there,

I am using a Try catch statement and I can return the Exception.Message
fine..but i want to catch a particular SQL error 1205 (locking). How do I say
:

catch (System.Exception ex)
{
//the below line is my interpretation of what I want to say!!
if (ex.SQLERRORCODE == 1205) {
do something else aswell as display label
}
lblError.Text="SQL Error [" + ex.Message + "]";
}
Or is it that .NET can't trap the code itself and I have to obtain this
through a return parameter of the SP??

Thanks,
 
Use SqlException instead. This one should provide detailed information
about the error (Number property or Errors collection).
 
Hello,

As Patrice said, catch SqlException specifically and check its Number
property.

HTH

message HI there,

I am using a Try catch statement and I can return the Exception.Message
fine..but i want to catch a particular SQL error 1205 (locking). How do I
say
:

catch (System.Exception ex)
{
//the below line is my interpretation of what I want to say!!
if (ex.SQLERRORCODE == 1205) {
do something else aswell as display label
}
lblError.Text="SQL Error [" + ex.Message + "]";
}
Or is it that .NET can't trap the code itself and I have to obtain this
through a return parameter of the SP??

Thanks,
 
*embarrased*

thanks!

Patrice said:
Use SqlException instead. This one should provide detailed information
about the error (Number property or Errors collection).

--
Patrice

louise raisbeck said:
HI there,

I am using a Try catch statement and I can return the Exception.Message
fine..but i want to catch a particular SQL error 1205 (locking). How do I say
:

catch (System.Exception ex)
{
//the below line is my interpretation of what I want to say!!
if (ex.SQLERRORCODE == 1205) {
do something else aswell as display label
}
lblError.Text="SQL Error [" + ex.Message + "]";
}
Or is it that .NET can't trap the code itself and I have to obtain this
through a return parameter of the SP??

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top