locked
Test connection with short timeout RRS feed

  • Question

  • I wrote a very small app to test some connection behaviours, so i started with the following connection string:

    Data Source=localhost;Initial Catalog=MyDB;Connection Timeout=1;Connect Timeout=1;

    Because I put a password on the server, after about 200ms I receive an error, that the user can't be logged on - perfect.
    But now I want to test what happens if I write "localhost2" instead:
    After about 9.3 Seconds !!! I'm receiving the error, that the Server is not known.
    How can I speed up this test? I want the connection to fail within a second if the server can't be reached. So Connection Timeout and Connect Timeout are not really working. Is there any other way, then setting up a timer?

    Thanks ...
    Friday, December 7, 2007 12:32 PM

All replies

  • Have you tried to use ConnectionTimeout property of the Connection class? Do not forget to remove connection timeout settings from the connection string in this case.

    Sunday, December 9, 2007 1:41 PM
  • Hi

     

    As ConnectionTimeout in Connection class is a readonly property which get the time in sec when connection will time out. I think we can set this property by keeping connection time out in connection string it self, default value for this connection time out is 30 sec, try to work out with keeping connection time out in connection string as 1 sec.

     

    Thanks,

    Monday, December 10, 2007 5:34 AM
  • I'm still confrontated with this issue. Any suggestions?

    Thursday, December 20, 2007 1:59 PM
  • Have you tried to use ConnectionTimeout property? Is it same result?

    Friday, December 21, 2007 2:15 AM
  • Yeah, i tried both. It seems that it is just the network service that takes to long to recognize the address won't be available.

     

    Friday, December 21, 2007 5:37 AM