SqlConnection :: No Exception Raised w/o Network

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leito
    New Member
    • Apr 2010
    • 58

    #1

    SqlConnection :: No Exception Raised w/o Network

    Hello,

    First the context: In my C# application form, I use an SqlConnection to access a Microsoft SQL Server located on a remote server:
    Code:
    connection = new SqlConnection(strConnection);
    try {
       connection.Open();
    } catch {
       return;
    }
    I want to manage errors when my network cable is unplugged. So I thought that treating the exception raised by the SqlConnection.O pen() method would do it.

    Now, my problem is the exception which should be raised when I unplugg my cable is not always.
    Especially, it seems that when I process successfully a command, then unplug my cable, the next connection I'll try to open won't raised any exception.

    That's a bit annoying... no network cable, and the Open() method does not raise any exception... -_-

    Any ideas?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do you .Close() your connection before the next open?

    Comment

    • Leito
      New Member
      • Apr 2010
      • 58

      #3
      Originally posted by Plater
      Do you .Close() your connection before the next open?
      Yes, I always .Close() my connection.
      .Close() and .Dispose() !

      Besides, I always use another instance of SqlConnection for each new connection I want to open.

      Comment

      • Leito
        New Member
        • Apr 2010
        • 58

        #4
        Nobody? :/

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Well its not the nicest thing, but you could listen for WMI events about adapter states and look for the "unplugged" event?

          Comment

          Working...