none
Catch a specific exception RRS feed

  • Question

  • Hi All,

    I am using VS 2013 to create my windows application. In my application in a class I am firing sql query which is been enclosed in the try catch block. I have written a specific catch  for SQLException. Now I have a separate treatment for collation conflict error. So I have a separate function that should be executed only if the exception is due to collation conflict.
    How I can separate out the collation conflict exception in sql exception. Is there anything? May be something like errorNo or something else.

    Regards,
    Girish

    Tuesday, January 21, 2014 1:35 PM

Answers

  • Your SqlException will have an Errors collection of SqlError. You can loop through these errors and look for property "Number" = 468 for collation conflict.


    Bob - www.crowcoder.com

    Tuesday, January 21, 2014 1:55 PM

All replies

  • Your SqlException will have an Errors collection of SqlError. You can loop through these errors and look for property "Number" = 468 for collation conflict.


    Bob - www.crowcoder.com

    Tuesday, January 21, 2014 1:55 PM
  • As Molku said you'll have to use the exception details.  You cannot create a separate catch block based on the exception details.  You'll have to use the general SqlException block and then filter from there.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Tuesday, January 21, 2014 3:58 PM
    Moderator
  • Hi Bob,

    Thanks for the reply. It looks like this will work for me. But for Collation conflict I am getting Error No: 451 and not 468.
    Am I missing something?
     Can I get some link where I can get list of these error Nos from where I can verify the Error Number?

    Regards,
    Girish

    Wednesday, January 22, 2014 3:16 AM
  • Hi Bob,

    I got the answer of my question and as well as the list of error codes.
    Thanks for your help.

    Regards,
    Girish

    Wednesday, January 22, 2014 3:37 AM
  • Hi Bob,

    I got the answer of my question and as well as the list of error codes.
    Thanks for your help.

    Regards,
    Girish

    Glad to hear it. It looks like there are many different collation related errors.

    Bob - www.crowcoder.com

    Wednesday, January 22, 2014 2:21 PM