Question Enumerate SQL Server Names and associated databases

alorenzini

New member
Joined
Nov 16, 2015
Messages
1
Location
Sioux Falls, South Dakota
Programming Experience
3-5
I am having a heck of time. I am looking for a way to enumerate SQL Servers in a combo box and then based on what is selected in the server combo box display the appropriate list of databases for that selected server in another combo box and once the database is selected then open the main form which is basically a dashboard for a document management application when I get that far.
\ I have been looking for the last few days for an example and am having no luck. I have seen bits and pieces using smo but does not serve quite my purpose. I am currently using VS2012. Any ideas would be do helpful.

Thank you,

Art Lorenzini
Sioux Falls,S D
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
I am having a heck of time. I am looking for a way to enumerate SQL Servers in a combo box and then based on what is selected in the server combo box display the appropriate list of databases for that selected server in another combo box and once the database is selected then open the main form which is basically a dashboard for a document management application when I get that far.
\ I have been looking for the last few days for an example and am having no luck. I have seen bits and pieces using smo but does not serve quite my purpose. I am currently using VS2012. Any ideas would be do helpful.

Thank you,

Art Lorenzini
Sioux Falls,S D
There's a couple of ways to do that: SQL Server query to find all current database names - Stack Overflow
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,345
Location
Sydney, Australia
Programming Experience
10+
Check out the code in the OptionsDialogue form of this example:

Protected Configuration (Encrypting Config Files)

It uses the SqlDataSourceEnumerator class to get the instance names and the SqlConnection.GetSchema method to get the database list for an instance. The relevant code is in the DropDown event handlers for the ComboBox controls.
 
Top Bottom