Finding SQL server

J

Jan Timmer

Hello all,

I have an (winforms) application that uses 3 different databases (MS
SQLserver 2000) that may be located in 1 or more SQL servers.
When run for the first time the user is presented a form where he can type
in the name of the SQL server and the database.
The user can then test the connection and save the configuration.
Now I want to make things a little bit easier by presenting the user a list
of available SQL servers and if possible database where he can choose from.

How do I go about?

Tia

Jan
 
G

Guest

Hi

Add the reference Microsoft SQLDMO Object library. This is a COM Component.
Then add a combo box in your form where you wish to show the list of servers.
And below written code can be used to fill the combo box

Dim ServerNames As SQLDMO.NameList
Dim ServerName As String
Dim SQLApp As SQLDMO.Application = New SQLDMO.Application
ServerNames = SQLApp.ListAvailableSQLServers()
For Each ServerName In ServerNames
ComboBox1.Items.Add(ServerName.Trim)
Next

Regards
Sooraj
Microsoft Community Star
 
R

Rami Saad

Hello Tia,

Here is a link that perfectly answers your questions. IT will help you
understand how to code an application in order to get the list of available
servers on the network:
http://www.codeproject.com/cs/database/LocatingSql.asp?df=100&forumid=30622&
exp=0&select=845289
hope this helps you solve your problem.
If you still have questions, don't hesitate to post/reply back.

Regards,
Rami Saad
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
J

Jan Timmer

Sooraj,

Thanks a lot!

I'll try it out.

Jan

Sooraj PM said:
Hi

Add the reference Microsoft SQLDMO Object library. This is a COM Component.
Then add a combo box in your form where you wish to show the list of servers.
And below written code can be used to fill the combo box

Dim ServerNames As SQLDMO.NameList
Dim ServerName As String
Dim SQLApp As SQLDMO.Application = New SQLDMO.Application
ServerNames = SQLApp.ListAvailableSQLServers()
For Each ServerName In ServerNames
ComboBox1.Items.Add(ServerName.Trim)
Next

Regards
Sooraj
Microsoft Community Star
 
S

Sushil Chordia

Hi Jan,
In Whidbey Beta (aka Version 2.0) we have introduced a way to enumerate
servers on the network. This can be done using the following code snippet:
<code>
DataTable datatable1 = SqlDataSourceEnumerator.Instance.GetDataSources();
</code>
If you are using Everett, you can use the SQLDMO library as pointed by
Sooraj or using Native OLEDB enumeration to enumerate exisiting server on
the network.
 
J

Jan Timmer

Thank you Sushil,

Very interesting!

I have saved your answer for future use. This is something I definetaly am
going to need when we are updgrading to Whidbey.

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top