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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse servers dialogue 1

Status
Not open for further replies.

keithinuk

Technical User
May 14, 2002
56
0
0
GB
I'm trying to provide a server lookup dialgue for my users at login time so they can select a specific instance of SQL server 2000. When I sign in to SQL Query Analyzer I get the sort of dialogue I'm aiming for by clicking the elipsis buttom ([...]).

Can somebody point me in the right direction please.

Thanks in advance
Keith

In case I forget to say "Thank you" I'll say it now - thank you for your help !!!
 
I just built an app that does exactly this.
You will need to reference SQLDMO (sp2 or better) then create an instance of the application object and the a variable for a namelist object. You then query the application objects listservers method which returns a namelist collection into the namelist object..

It will do a good job of returning 146 servers if they are up and not listing the ones that are down...

Code could look something like....
(creates a filterable datatable)

If Not IsNothing(dt) Then
ds.Tables.Remove("DefTab")
dt = Nothing
dv = Nothing
End If

dt = New DataTable("DefTab")
dv = New DataView(dt)

Dim sdo As New SQLDMO.Application()
Dim nl As SQLDMO.NameList
Dim myDataRow As DataRow
Dim strPCName As String
nl = sdo.ListAvailableSQLServers

dt.Columns.Add("ServerName", System.Type.GetType("System.String"))
dt.Columns.Add("Plaza", System.Type.GetType("System.String"))

ds.Tables.Add("DefTab")

Dim x As Integer
For x = 1 To nl.Count
myDataRow = dt.NewRow()
If nl.Item(x) = "(local)" Then
strPCName = SystemInformation.ComputerName
myDataRow(0) = strPCName
myDataRow(1) = Strings.Left(CStr(strPCName), 3)
Else
myDataRow(0) = nl.Item(x)
myDataRow(1) = Strings.Left(CStr(nl.Item(x)), 3)
End If
dt.Rows.Add(myDataRow)

Next
dv.Sort = ("ServerName")
Dim t As DataTable

Dim oRow As DataRow
Dim oCol As DataColumn

For Each oRow In dv.Table.Rows
'For Each oCol In dv.Table.Columns
'MsgBox(oRow(oCol))
If Strings.InStr(oRow(0), "\") > 0 Then
Else
AddMonitor(oRow(0), oRow(1))
End If

'Next
Next

HTH

Rob
 
What a star !!!!!!!!!!

Thanks for the code sample too !!!!!!!!

Keith

In case I forget to say "Thank you" I'll say it now - thank you for your help !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top