Enumerating SQL Servers from .NET 2.0

There’s a cool new .net 2.0 feature I didn’t know about until I needed to do this a few days ago. If your application has FullTrust, you can use the System.Data.Sql.SqlDataSourceEnumerator to get a list of available SQL servers (2000 and 2005 only). The query returns a DataTable which you can just attach to a combobox or drop down list.

 Dim instance As SqlDataSourceEnumerator =      SqlDataSourceEnumerator.Instance
 Dim dt As DataTable = instance.GetDataSources()

Remember, though, this requires the assembly to have full trust. There is not a specific permission you can apply to use this otherwise.

Don’t Forget: www.acehaid.org

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.