List Installed SQL Server Instances on machine and LAN using C# and VB.Net
 
Author:
Filed Under: C#.Net  |  VB.Net  |  Snippets
Published Date: Dec 18, 2010
Views: 2690
 

Abstract: Here Mudassar Ahmed Khan has explained how to list the installed instances of SQL Server on machine and LAN Network using C# and VB.Net

Comments:  2

 

This is a very short code snippet where I will explain how to list the SQL Server instances that are installed on your machine and on the network connected to your machine.
Namespaces

You will need to import the following namespaces

C#

using System.Data;
using System.Data.Sql;
 
VB.Net

Imports System.Data
Imports System.Data.Sql

SqlDataSourceEnumerator class
 
The SqlDataSourceEnumerator class allows you to get the Instances of the SQL Server installed on the machine and also on the network the machine is connected to. You can find more information on the same on the following MSDN article
 
 
Now here I’ll get the installed instances of the SQL Server and bind them to a DropDownList Control
 
C#
 
DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dt.Rows)
{
    ddlInstances.Items.Add(string.Concat(dr["ServerName"], "\\", dr["InstanceName"]));
}
 
VB.Net

Dim dt AsDataTable = SqlDataSourceEnumerator.Instance.GetDataSources
ForEach dr As DataRow In dt.Rows
     ddlInstances.Items.Add(String.Concat(dr("ServerName"), "\\", dr("InstanceName")))
Next
 
Screenshot

List installed SQL Server instances on machine and network using C# and VB.Net

That’s it in this article. Hope you liked it.









Related Articles



Comments



Add comments

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment

Please note that all comments are moderated and will be deleted if they are
  • Not relavant to the article
  • Spam
  • Advertising campaigns or links to other sites
  • Abusive content.
Please do not post code, scripts or snippets.

Name*: Required
Email*: Required
Comment*: Required
Security code*: CaptchaInvalid Security Code
  Submit