tags:

views:

130

answers:

3

Hi,

I'm trying to connect to a server that the user inputs. When the server doesn't exist, I'd like to give a quick feedback to the end-user so he can correct what he's typed.

Is there any way to test if a server exists before trying to connect ?

Thanks

A: 

You can use SQL Server Management Objects (SMO) to get a list of SQL Servers. There is a sample of how to get a list of servers here. The enumeration of the servers can take a while but you could always start it in the background when the application loads so that it is ready when the user needs to select a server.

TLiebe
Thanks I'll check it out, although I don't understand how I could list all available servers without specifying anything.And I need the solution to work for both Oracle and MsSQL.
leo
Finding the Oracle servers might be a problem. The SMO object has a EnumAvailableSqlServers function that will scan the network for all SQL servers. It takes a few seconds to complete but it's great for building a form where the user can see all the SQL servers that are visible on the network.
TLiebe
A: 

You can always ping the server or check if a given port is open] but this won't guarantee you that this server won't get offline just before connecting for real.

Darin Dimitrov
+2  A: 

Does your DBConnection have a ConnectionTimeout property? Try setting this to a small number.

Pbirkoff
Thanks I'll try that.
leo