.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> DataBase >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Enumerate SQL Server Instances in Network

Posted By:Kirtan       Posted Date: June 01, 2010    Points: 25    Category: DataBase    URL: http://www.dotnetspark.com  

In this article I will teach you how to get names and all other information of sql server instances that are in network. This type of coding will help you in situation where you want to show selection for the user what sqlserver instance he want to connect to.
 

Introduction:

In this article I will teach you how to get names and all other information of sql server instances that are in network.
This type of coding will help you in situation where you want to show selection for the user what sqlserver instance he want to connect to.

Implementation:

For getting all instances of the sql server running on network computers we are going to us namespace

System.Data.Sql;

Import the namespace by writing statement

using System.Data.Sql;

Now we can get all the instance information in DataTable by executing the method GetDataSources() of the

SqlDataSourceEnumerator
class

So simply we will write the code.

Like below to retrieve the data table containing information about all the instances of slqserver. Then we can manipulate that datatable to show information as our project requirement.

I have setup GUI like below as I want to show all the information like below




private void Form1_Load(object sender, EventArgs e)
{
    /* get data sources */
    DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();

    /* Do whatever you want to do with that table; */

    comboBox1.Items.Clear();
    foreach (DataRow dr in dt.Rows)
    {
        comboBox1.Items.Add(dr[0].ToString());
    }
    dataGridView1.DataSource = dt;
}

As you can see we can get more information not only name of the sql server instance like

ServerName

Instance Name

Is Clustered

And version also

Just two lines of code and you have enumerated all the instances of the sqlserver instances in the network

Conclusion:

Article teaches how to enumerate Sqlserver instances in the network .

You can download sample application by clicking below link

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend