Link to home
Start Free TrialLog in
Avatar of Mike_Stevens
Mike_StevensFlag for United States of America

asked on

List available SQL Servers using VB.NET

I am looking for a reliable way to search for all available SQL Servers on a network.   I then need to be able to list the databases for a particular server.  I have done this in the past in VB6 applications using SQLDMO without problem.  I am wondering if their is a better or different way to do this using VB.NET and the .NET Framework version 3.5
Avatar of ladarling
ladarling
Flag of United States of America image

Try:
Dim dtSQL As New DataTable
dtSQL = Sql.SqlDataSourceEnumerator.Instance.GetDataSources
DataGridView1.DataSource = dtSQL.AsDataView
 
This should query your network for all available instances of SQL server 2000 or 2005.
ASKER CERTIFIED SOLUTION
Avatar of ladarling
ladarling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike_Stevens

ASKER

I tried the second methid you just posted.  It works but it is very, very slow
How big is your network, out of curiousity? The server enum takes about 10 seconds for me, but we only have around 200 workcenters.
Using the first method, you will just get the SQL server names available. Once you 'weed out' the non-server machines, you can then run the stored procedure 'sp_databases' against the servers to enumerate the db's.