Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding all SQL servers on the network

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello,

I am making a data extraction software from any sql server database, and i want my software to discover all servers which are on the network, so I can select the one I want.

Do you know how I can do that?

Thank you

David
 
Build an application that uses/references the SQLDMO Com object.

Create an instance of the application object
use the ListAvailableSQLServers method of it to bring back a NameList object (array of servers)

at that point loop throught the array and do what ever processing you need..

E.G. (in VB - builds an ado Recordset (public variable declared at a project level) object to store and use for later processing)
[blue]

Set rs = New ADODB.Recordset
rs.fields.Append "ServerName", adVarChar, 50
rs.Open

Dim sdo As SQLDMO.Application
Dim nl As SQLDMO.NameList
Dim field as string
Dim values [green]'A variant that will be used as an array when sending data to the recordset via the addnew method[/green]

field = "ServerName"
Set sdo = New SQLDMO.Application

Set nl = sdo.ListAvailableSQLServers
Dim X As Integer


For X = 1 To nl.Count
values = array(nl(X))
rs.AddNew fields, values
rs.update
Next

Set sdo = Nothing
Set nl = Nothing

[/blue]
 
Hey NoCool,

I've not used the SQL references before and I'm trying to understand the type of the variant values.

Can you tell me how it manages to go into the recordset but I can't convert it using CStr() and put into a ListBox

As once it is in the recordset I can mess about with it. And then put it into a ListBox, but I'd like to remove this extra step.


Cheers,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top