none
SQLException - how to determine if the exception was caused by connection problem? RRS feed

  • Question

  • Hi,

     

       When a SQLException is catched (in vb.net), how to determine if the exception was caused by connection problem (network problem, database is down, etc).

     

       Thanks.

     

    Cathie

    Monday, July 16, 2007 8:44 PM

Answers

  • What you could do is to put specific parts of the code into separate exception handlers, so you might know what is wrong. For example when you try to open connection, put only Open method into try part and if opening fails, you know that something wrong. Why do you need to know exact reason? Anything specific?
    Wednesday, July 18, 2007 10:37 AM
    Moderator

All replies

  • You could do it based on error code. SqlException has property called ErrorCode. I believe this is the only way to check specific error, but I am not sure if those error codes do not change with time.

    Tuesday, July 17, 2007 10:29 AM
    Moderator
  • I tried to use errorcode, but seems that the errorcode changes.

     

    Thanks.

    Tuesday, July 17, 2007 1:27 PM
  • What you could do is to put specific parts of the code into separate exception handlers, so you might know what is wrong. For example when you try to open connection, put only Open method into try part and if opening fails, you know that something wrong. Why do you need to know exact reason? Anything specific?
    Wednesday, July 18, 2007 10:37 AM
    Moderator
  • Hi,   I am using microsoft application blocks, the connection is taken care of by the application blocks.

    Wednesday, July 18, 2007 7:17 PM
  • Then you could modify application blocks or you need to use your own code.
    Thursday, July 19, 2007 10:32 AM
    Moderator