What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 42824 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > List All SQL Server Instances in Combo ...
Johnbhatt

List All SQL Server Instances in Combo

 Code Snippet posted by: Johnbhatt | Posted on: 7/20/2012 | Category: C# Codes | Views: 395 | Status: [Member] | Points: 40 | Alert Moderator   


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++)
{
comboBox1.Items.Add(SerNames.Rows[index][0].ToString()+"\\"+SerNames.Rows[1].ToString());
}
}

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.

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 3:44:21 PM