Monday, April 19, 2010

Get all running Sql Server instances name within network using Asp.Net C# vB.Net




Please visit my new Web Site WWW.Codedisplay.com



Basically who did sql server operational job in any organization sometimes requires to get all running sql server instances name. Here in this asp.net C# VB.Net article i will give you a simple code snippet how you can achieve this. After running my sample code you will get all running sql server instances in your Local Area Network (LAN)/Network even from your local PC like below:

Sql Server Instances name

To run the below code sample just add a page in your project & add a GridView control. Then under page_load event write the below code sample:

C# complete Code:
using System;
using System.Data;
using System.Data.Sql;

public partial class SQL_Insances : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlDataSourceEnumerator SqlEnumerator;
            SqlEnumerator = SqlDataSourceEnumerator.Instance;
            DataTable dTable = SqlEnumerator.GetDataSources();
            GridView1.DataSource = dTable;
            GridView1.DataBind();
        }
    }
}
VB.Net Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (IsPostBack=False) Then
            Dim SqlEnumerator As System.Data.Sql.SqlDataSourceEnumerator
            SqlEnumerator = System.Data.Sql.SqlDataSourceEnumerator.Instance
            Dim dTable As System.Data.DataTable
            dTable = SqlEnumerator.GetDataSources()
            GridView1.DataSource = dTable
            GridView1.DataBind()
        End If
    End Sub

3 comments:

Unknown said...

Hi Shawpnendu,

This was a nice example for listing the SQL Server instances. The best thing about this code is, it works even there is no LAN in your system, which is not possible using the SQLDMO object.

Thanks
Abhijeet Kanjilal
Senior Developer
Navsoft, Kolkata

Anonymous said...

Thanks a lot

Anonymous said...

Thanks!! This works very well..

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash