How to identify whether an SQLException is TimeOUtException or not?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajasoorya
    New Member
    • Feb 2008
    • 1

    How to identify whether an SQLException is TimeOUtException or not?

    Hi,

    In my application.... i want to identify whther the SQLException caught is a Timeout or any other SQLException. The reason being, i have to show a different msg to the user in case it is a timeout error.

    Thank you in advance
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Are you using framework 2.0? Have you identified error numbers for these?

    Comment

    • jjvainav
      New Member
      • Feb 2008
      • 25

      #3
      When a SqlException occurs you can loop through the errors and get the error code for the Exception

      Code:
      catch (SqlException ex)
      {
          foreach(SqlError error in ex.Errors)
          {
              // error.Number
          }
      }
      If the error occurs duing a connection, this number will represent a socket error, such as 10060 for "An error has occurred while establishing a connection to the server." Otherwise if you are executing a sql command, this correspond to an error on your Sql Server. You can find all the errors by querying the master.dbo.sysm essages table, and error 17197 corresponds to "Login failed due to timeout"

      Hope this helps.

      Comment

      Working...