none
Different types of timeout RRS feed

  • Question

  • I'm executing a command via SqlCommand, with CommandTimeout set to 30 seconds.

    Timeout can happen in the following 2 scenarios:

    1. Connection to server failed.
    2. Connection succeeded, but execution lasted longer than 30 secs.

    Is there a way to distinguish between the 2?
    Wednesday, December 16, 2009 12:40 PM

All replies

  • For 1. you will have something like:

    System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

    For 2.

    System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

    Then of course, if you timeout on connection open, then you will not be able to try to execute the command :-)

    HTH
    //Michael
    This posting is provided "AS IS" with no warranties.
    Wednesday, December 16, 2009 1:50 PM
  • Thanks for your response, Michael.


    I don't want to rely on exception texts; they might change in any upcoming version of .Net.

    About your timing-out on connection suggestion, that's a valid practice of course, but in my scenario, it involves a lot of refactoring which I'm trying to avoid.
    In addition, reconnecting on any command can pose significant performance overhead.

    More suggestions?
    Wednesday, December 16, 2009 1:59 PM