Click here to Skip to main content
12,557,148 members (30,693 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked

How to enum SQL Server instances in network

, 13 Feb 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip is desired for those who want to list all available SQl Server instances that are in a network.


Sometimes we need to list all available SQL Server instances in LAN to gain information about them. For example, it's useful when we need to write a custom installer for our database.

This tip shows us how to solves this problem. 

Using the code  

The code is as simple as it's possible Wink | ;)

What you need to test the code? 

  1. Create new project (windows application), 
  2. Add: 
    • 1 Label
    • 1 ComboBox (change it name to: CmbSQLInstance
    • 1 DataGridView  (change it name to: DGVSQLInstances)

Before you start coding, you need to set reference to  System.Data.Sql namespace (as is described here:

'declare variables
Dim dt As Data.DataTable = Nothing, dr As Data.DataRow = Nothing

    'get sql server instances in to DataTable object
    dt = Sql.SqlDataSourceEnumerator.Instance.GetDataSources()

    'load data in to ComboBox
    For Each dr In dt.Rows
    'load data in to DataGridView
    Me.DGVSQLInstances.DataSource = dt

Catch ex As System.Data.SqlClient.SqlException
    MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")

Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error!")

    'clean up ;)
    dr = Nothing
    dt = Nothing
End Try 



  • 2013/02/11 - First version.
  • 2013/02/13 - source files added


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Maciej Los
Team Leader
Poland Poland
I'm a lawyer, teacher/trainer and author of VBA programming book (only polish version). Programming is my hobby!
  2. C#
  3. C++
  4. SQL
  5. Linq
  6. XML & XSL

You may also be interested in...


Comments and Discussions

QuestionNot guaranteed to work always Pin
rajeshrdas20083-Mar-16 18:25
memberrajeshrdas20083-Mar-16 18:25 
AnswerRe: Not guaranteed to work always Pin
Maciej Los3-Mar-16 19:59
protectorMaciej Los3-Mar-16 19:59 
GeneralMy vote of 5 Pin
Sergey Alexandrovich Kryukov13-Aug-14 6:22
mvpSergey Alexandrovich Kryukov13-Aug-14 6:22 
GeneralRe: My vote of 5 Pin
Maciej Los13-Aug-14 10:25
mvpMaciej Los13-Aug-14 10:25 
QuestionEnum also Available Databases Pin
Member 1094242312-Jul-14 13:17
memberMember 1094242312-Jul-14 13:17 
AnswerRe: Enum also Available Databases Pin
Maciej Los12-Jul-14 22:17
mvpMaciej Los12-Jul-14 22:17 
GeneralMy vote of 5 Pin
Adarsh chauhan14-Aug-13 2:12
memberAdarsh chauhan14-Aug-13 2:12 
Nice and to the point.. Smile | :)
GeneralRe: My vote of 5 Pin
Maciej Los14-Aug-13 2:19
mvpMaciej Los14-Aug-13 2:19 
QuestionNice.. Pin
Raja Sekhar S1-Aug-13 1:47
professionalRaja Sekhar S1-Aug-13 1:47 
AnswerRe: Nice.. Pin
Maciej Los1-Aug-13 1:49
mvpMaciej Los1-Aug-13 1:49 
GeneralMy vote of 5 Pin
VitorHugoGarcia26-Feb-13 4:56
memberVitorHugoGarcia26-Feb-13 4:56 
AnswerRe: My vote of 5 Pin
Maciej Los2-Mar-13 1:10
mvpMaciej Los2-Mar-13 1:10 
GeneralRe: My vote of 5 Pin
VitorHugoGarcia3-Mar-13 22:37
memberVitorHugoGarcia3-Mar-13 22:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 13 Feb 2013
Article Copyright 2013 by Maciej Los
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid