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;
}
}
}