Check if server exists

Posted by buhtla on Stack Overflow See other posts from Stack Overflow or by buhtla
Published on 2010-03-12T13:06:27Z Indexed on 2010/03/12 13:07 UTC
Read the original article Hit count: 250

Filed under:
|

Here is the problem. User can enter server name and connection string for database. If server is not accessible (wrong address, firewalls or any other issue), I want to be aware of this as quickly as possible.

If I'm using sqlConnection and try to connect to a non-accessible server this takes very long (I think more than 1 minute!). This has nothing to do with connection timeout btw so setting this property won't help.

My idea is to first try to ping server and if I get response (which means server is accessible from the point of application), than proceed with sqlConnection. If there is no response from ping, operation is aborted and user is properly notified.

Is there any better way of doing this? Any idea would be welcome.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET