To list the server running in the listbox or the grid we can use following code and give user a option to select the server to whom he wants to connect
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
namespace ListSQLServer
{
public partial class serverListing : Form
{
public serverListing()
{
InitializeComponent();
}
private void listButton_Click(object sender, EventArgs e)
{
DataTable dtServer = SqlDataSourceEnumerator.Instance.GetDataSources();
serverDetailsGrid.DataSource = dtServer;
}
}
}
you will get the following result in the grid
