Trapping a particular SQL Error Code

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,
 
P

Patrice

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

Siva M

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,
 
G

Guest

*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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top