Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Get all SQL Severs on the Local Area network using SQL Server Management Object in .net 2.0.

Author: DevAsp Team
Download Source Code :

In this simple article you will learn how you can Get all SQL Severs on the Local Area network using SQL Server Management Object.

Simply just create New Project of C#.


Firstly Add Reference of Microsoft.SqlServer.Smo from references.


Microsoft.SqlServer.Smo this is SQL Server Management Object Namespace. This is use for SQL Server Management Operations.


Now drag one Button, one comboBox and one label on the form



Now just write code on Form Load Event



private void Form1_Load(object sender, EventArgs e)


            this.Text= "Get All SQL Servers";


            Button1.Text = "Load All Servers";




Now write code on Button Click Event


private void Button1_Click(object sender, EventArgs e)



            DataTable dtable = SmoApplication.EnumAvailableSqlServers(false);

            string ServerName;


            foreach (DataRow dr in dtable.Rows)


                ServerName = dr["Server"].ToString();


                if (!Convert.IsDBNull(dr["Instance"]) & dr["Instance"].ToString().Length > 0)

                    ServerName += "\\" + dr["Instance"].ToString();


                if (ComboBoxServer1.Items.IndexOf(ServerName) < 0)



                if (ComboBoxServer1.Items.Count > 0)

                    ComboBoxServer1.SelectedIndex = 0;





After Pressing this button Your All SQL Server on Local Area Network or on your PC Load into the ComboBox.

Article Comments
Thanks Great.

This Solution Helps me lot.

Posted on 5/4/2010 3:05:39 AM by Pravin Wagh


It is working and i got the code desired.

once again thanks.

Posted on 10/23/2010 7:36:48 PM by Vinay

Add Article Comment:
Name :
Email Address :
Comments :
<< What is Client Server Architecture. (Part-1)

Disclaimer - Privacy
© 2002-2017