List All SQL Server Instances in Combo

Posted by Johnbhatt under C# category on | Points: 40 | Views : 1535
private void Form1_Load(object sender, EventArgs e)
panel1.Visible = false;
groupBox1.Visible = false;
label9.Visible = true;
label9.TextAlign = ContentAlignment.MiddleCenter;
SqlDataSourceEnumerator SerInstances = SqlDataSourceEnumerator.Instance;
DataTable SerNames = SerInstances.GetDataSources();
for (int index = 0; index <= SerNames.Rows.Count - 1; index++)

Description of Above Code:

We have placed rest design in Panel and Groupbox so we set that invisible on Form Load. Please Make a Conncetion First.. is Label9 and we set is Visible and aligned.

Now main task is to List Sql Servers on Network. For this we used SqlDataSourceEnumerator class.
In Next Line we take a DataTable and stored ServerInstances into that.
Rest is Simple, We added all items into Listbox. Column 0 contains Machine name and Column 1 contains Instance Name. So we combined that at the Time of Adding to ComboBox Control.

Comments or Responses

Login to post response