Refer to the MSDN Article community Server instance.
In the demo, Insus. NET displays the instance in the DropDownList control. First, pull a DropDownList control in. aspx:
Copy codeThe Code is as follows:
Server: <asp: DropDownList ID = "DropDownListInstance" runat = "server"> </asp: DropDownList>
Write in the Page_Load event:
Copy codeThe Code is as follows:
View Code
Protected void Page_Load (object sender, EventArgs e)
{
DataTable dataTable = SqlDataSourceEnumerator. Instance. GetDataSources ();
Foreach (DataRow dr in dataTable. Rows)
{
If (string. IsNullOrEmpty (dr ["InstanceName"]. ToString ()))
This. DropDownListInstance. Items. Add (string. Concat (dr ["ServerName"]);
Else
This. DropDownListInstance. Items. Add (string. Concat (dr ["ServerName"], "\", dr ["InstanceName"]);
}
}
As a result, the Insus. NET laptop is installed with SQL Server 2012 and SQL Server 2008 R2, so two SQL Server instances are displayed.