Trapping a particular SQL Error Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • louise raisbeck

    Trapping a particular SQL Error Code

    HI there,

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

    catch (System.Excepti on ex)
    {
    //the below line is my interpretation of what I want to say!!
    if (ex.SQLERRORCOD E == 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,

  • Patrice

    #2
    Re: Trapping a particular SQL Error Code

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

    --
    Patrice

    "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> a écrit dans le
    message de news:3B686062-569D-491D-A2F1-72E55F5236F0@mi crosoft.com...[color=blue]
    > HI there,
    >
    > I am using a Try catch statement and I can return the Exception.Messa ge
    > fine..but i want to catch a particular SQL error 1205 (locking). How do I[/color]
    say[color=blue]
    > :
    >
    > catch (System.Excepti on ex)
    > {
    > //the below line is my interpretation of what I want to say!!
    > if (ex.SQLERRORCOD E == 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,
    >[/color]


    Comment

    • Siva M

      #3
      Re: Trapping a particular SQL Error Code

      Hello,

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

      HTH

      "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> wrote in
      message news:3B686062-569D-491D-A2F1-72E55F5236F0@mi crosoft.com...
      HI there,

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

      catch (System.Excepti on ex)
      {
      //the below line is my interpretation of what I want to say!!
      if (ex.SQLERRORCOD E == 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,


      Comment

      • louise raisbeck

        #4
        Re: Trapping a particular SQL Error Code

        *embarrased*

        thanks!

        "Patrice" wrote:
        [color=blue]
        > Use SqlException instead. This one should provide detailed information
        > about the error (Number property or Errors collection).
        >
        > --
        > Patrice
        >
        > "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> a écrit dans le
        > message de news:3B686062-569D-491D-A2F1-72E55F5236F0@mi crosoft.com...[color=green]
        > > HI there,
        > >
        > > I am using a Try catch statement and I can return the Exception.Messa ge
        > > fine..but i want to catch a particular SQL error 1205 (locking). How do I[/color]
        > say[color=green]
        > > :
        > >
        > > catch (System.Excepti on ex)
        > > {
        > > //the below line is my interpretation of what I want to say!!
        > > if (ex.SQLERRORCOD E == 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,
        > >[/color]
        >
        >
        >[/color]

        Comment

        • louise raisbeck

          #5
          Re: Trapping a particular SQL Error Code

          Thank you! Feeling very silly.

          "Siva M" wrote:
          [color=blue]
          > Hello,
          >
          > As Patrice said, catch SqlException specifically and check its Number
          > property.
          >
          > HTH
          >
          > "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> wrote in
          > message news:3B686062-569D-491D-A2F1-72E55F5236F0@mi crosoft.com...
          > HI there,
          >
          > I am using a Try catch statement and I can return the Exception.Messa ge
          > fine..but i want to catch a particular SQL error 1205 (locking). How do I
          > say
          > :
          >
          > catch (System.Excepti on ex)
          > {
          > //the below line is my interpretation of what I want to say!!
          > if (ex.SQLERRORCOD E == 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,
          >
          >
          >[/color]

          Comment

          Working...