Click here to Skip to main content
13,400,969 members (41,400 online)
Click here to Skip to main content
Add your own
alternative version


75 bookmarked
Posted 7 Nov 2007

SQL Server Network Instance Detector

, 7 Nov 2007
Rate this:
Please Sign up or sign in to vote.
A simple, ready-to-use control for C# beginners to detect all SQL Server instances in a network and then list all the databases hosted on the selected server

What is it?

Screenshot - MainImage.jpg

Control used in a sample application

Screenshot - Password.jpg

You have to give a username and password to retrieve all hosted databases. Note: is the assembly containing the SQLServersDetector control. contains the source code of the control, along with a sample application using the control.


It's a simple window control that can load all of the SQL Server instances in your local network and then load all of the databases on the selected server. I used SqlDataSourceEnumerator to load servers from the network.


I was writing code in C# that was related to the manipulation of data with more than one database. I found that it was difficult for a user to type the address of a server and database into the text input fields and then connect to them for further manipulation because there is always the chance of the sever name or path being misspelled. If a user by mistake inputs the wrong spelling of the server or database name and then clicks connect, it takes a long time to decide that the path is not valid and throw an exception. Then the user has to to check the spelling again and give the input again, which I think is always irritating. So, I decided to detect the server instances automatically and load databases from the server and so on...

Using the Control

The control is easy to use, as is any other Windows control in .NET. You just have to add a reference of the DLL that is provided with this article. Alternatively, add the project to your solution and add a reference of the project SqlServersDetector to your project. Then the control will appear in your Toolbox just like this.

Screenshot - Toolbox.jpg

Now you can simply drag and drop it onto your form.

Properties of the Control

You can use the following properties of the control if you need them.

//Property to get the connection string that is created 
//by using selected server, selected database, username and password.
lblConnectionString.Text = sqlServersDetector1.DBConnectionString;

//Property to get or set the text that is displayed on 
//upper left corner of the control
sqlServersDetector1.MainLabel = "All Servers";

//Property to get or set the text that of the label 
//against Servers combo box.
sqlServersDetector1.ServersLabel = "Servers";

//Property to get or set the text that of the label 
//against Databases combo box.
sqlServersDetector1.DatabasesLabel = "Database";

//Property to get the selected server instance.
string server = sqlServersDetector1.SelectedServer;

//Property to get the selected database.
string database = sqlServersDetector1.SelectedDatabase;

Using the Example Solution Provided with the Article

If any beginner doesn't know how to use the solution, just download the ZIP file and unzip it. Then open the SQLServerDetectionControl.sln solution file and run the project named TestAppForSQLServerControl. If you are still facing problems using this control, then feel free to ask.


  • 7 November, 2007 -- Original version posted


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Syed Mujtaba Hassan
Software Developer
Pakistan Pakistan
Syed Mujtaba Hassan
Software Engineer
Intelligentsia Software (Pvt) Ltd Islamabad Pakistan.

You may also be interested in...


Comments and Discussions

QuestionDefault Instances Pin
Cesar Esquivel2-Jul-13 7:18
memberCesar Esquivel2-Jul-13 7:18 
GeneralMy vote of 5 Pin
Kanasz Robert24-Sep-12 6:59
mvpKanasz Robert24-Sep-12 6:59 
Generalreference file ! Pin
sidra yaseen26-Aug-08 19:12
membersidra yaseen26-Aug-08 19:12 
GeneralRe: reference file ! Pin
Syed Mujtaba Hassan26-Aug-08 19:45
memberSyed Mujtaba Hassan26-Aug-08 19:45 
GeneralProb with VS 2008, SQL 2008 both SP1, .NET 3.5 SP1 [modified] Pin
Brian Hart16-Aug-08 19:28
memberBrian Hart16-Aug-08 19:28 
GeneralRe: Prob with VS 2008, SQL 2008 both SP1, .NET 3.5 SP1 Pin
pvandijk282-Sep-08 0:40
memberpvandijk282-Sep-08 0:40 
GeneralRe: Prob with VS 2008, SQL 2008 both SP1, .NET 3.5 SP1 Pin
pvandijk282-Sep-08 0:53
memberpvandijk282-Sep-08 0:53 
GeneralLimitations... Pin
Tor2k11-Feb-08 16:37
memberTor2k11-Feb-08 16:37 
GeneralRe: Limitations... Pin
Syed Mujtaba Hassan11-Feb-08 19:24
memberSyed Mujtaba Hassan11-Feb-08 19:24 
Generalproblem retrieving instance names Pin
Farhan Ali4-Dec-07 22:10
memberFarhan Ali4-Dec-07 22:10 

I have retrieved the server names on a network but not able to retrieve the instance name relevant to that server name.

this line extracting only server name.

comboServers.Items.Add(servers.Rows[i]["ServerName"] + "\\" + servers.Rows[i]["InstanceName"]);

please guide me.
GeneralRe: problem retrieving instance names Pin
Syed Mujtaba Hassan10-Dec-07 2:43
memberSyed Mujtaba Hassan10-Dec-07 2:43 
GeneralLimitation Pin
Ashutosh Bhawasinka17-Nov-07 11:48
memberAshutosh Bhawasinka17-Nov-07 11:48 
GeneralAlso NetServerEnum... Pin
Cristian Amarie14-Nov-07 8:09
memberCristian Amarie14-Nov-07 8:09 
QuestionAny problems like this one? Pin
michaeldjackson13-Nov-07 6:38
membermichaeldjackson13-Nov-07 6:38 
AnswerRe: Any problems like this one? Pin
Syed Mujtaba Hassan13-Nov-07 23:25
memberSyed Mujtaba Hassan13-Nov-07 23:25 
GeneralRe: Any problems like this one? Pin
michaeldjackson14-Nov-07 5:21
membermichaeldjackson14-Nov-07 5:21 
GeneralRe: Any problems like this one? Pin
Syed Mujtaba Hassan14-Nov-07 5:49
memberSyed Mujtaba Hassan14-Nov-07 5:49 
GeneralRe: Any problems like this one? Pin
michaeldjackson14-Nov-07 7:39
membermichaeldjackson14-Nov-07 7:39 
GeneralRe: Any problems like this one? Pin
Syed Mujtaba Hassan14-Nov-07 18:12
memberSyed Mujtaba Hassan14-Nov-07 18:12 
GeneralRe: Any problems like this one? Pin
michaeldjackson15-Nov-07 4:25
membermichaeldjackson15-Nov-07 4:25 
Generalintresting Pin
MichMsk8-Nov-07 3:18
memberMichMsk8-Nov-07 3:18 
GeneralRe: intresting Pin
Syed Mujtaba Hassan8-Nov-07 18:20
memberSyed Mujtaba Hassan8-Nov-07 18:20 
GeneralGood effort Pin
iamhaider7-Nov-07 23:23
memberiamhaider7-Nov-07 23:23 
GeneralVery handy Control Pin
Faheem A Saleem7-Nov-07 18:19
memberFaheem A Saleem7-Nov-07 18:19 
GeneralThis is quite cool Pin
Frank Kerrigan7-Nov-07 12:45
memberFrank Kerrigan7-Nov-07 12:45 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180218.2 | Last Updated 7 Nov 2007
Article Copyright 2007 by Syed Mujtaba Hassan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid