Enumerating SQL Server instances

Source: Internet
Author: User
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;

// The namespace introduced
Using system. Data. SQL;

Namespace enumsqlserver
{
Public partial class mainform: Form
{
Public mainform ()
{
Initializecomponent ();
}

Private void mainform_load (Object sender, eventargs E)
{
// Enumerate all available sqlserver instances in the local network
Sqldatasourceenumerator instance = sqldatasourceenumerator. instance;
// Return
//----------------------------------------------------------------------------
// SERVERNAME | Server Name
//----------------------------------------------------------------------------
// InstanceName | Name of the server instance. Blank if the server runs as the default instance
//----------------------------------------------------------------------------
// Isclustered | indicates whether the server belongs to a cluster.
//----------------------------------------------------------------------------
// Version | Server version (sqlserver2000 is 8.00.x, and sqlserver2005 is 9.00.x)
//----------------------------------------------------------------------------
Datatable dt = instance. getdatasources ();
// Bind
Cboserverlist. datasource = createcbodatasource (DT );
}

/// <Summary>
/// Obtain the combox Data Source
/// </Summary>
/// <Param name = "DT"> </param>
/// <Returns> </returns>
Private list <string> createcbodatasource (datatable DT)
{
List <string> List = new list <string> ();

Foreach (datarow DR in DT. Rows)
{
// Retrieve servername only
List. Add (Dr [0]. tostring ());
}

Return list;
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.