locked
How do you determine if a SQLException is due to a connection or query problem? RRS feed

  • Question

  • Is there a foolproof method for determining if a SQLException was caused by a query versus some connection-related problem?  My application should handle the two cases in very different ways, so it's important to cover every case.

    Any help would be appreciated.
    Wednesday, November 19, 2008 5:09 PM

All replies

  • Anyone?...
    Thursday, November 20, 2008 3:41 PM
  • As far as I know, there isn't an easy way to distinguish a connectivity exception from a query exception, except in the easy case where you are making the initial connection.  Granted, that is where most connectivity errors occur, but they can of course happen during queries as well, in which case I don't know of any good solution for you to determine whether it is a connectivity versus a query exception.  I am moving to the ADO.Net Data Providers Forum, in case someone there has a better suggestion.

    Friday, November 21, 2008 11:32 PM
  • Not sure if the below documentation helps but it may be worth taking a look:

     

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception(VS.71).aspx

     

     

    Friday, November 21, 2008 11:59 PM