March 19, 2008 at 12:58 pm
Anyone knows by any chance how to enumerate sql instances on a given subnet (e.g. 192.168.1.xxx)?
thanks
March 19, 2008 at 1:19 pm
Here's one way:
Imports Microsoft.SqlServer
Imports Microsoft.SqlServer.Management
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Server
Imports system.Data
Module Util
Public Sub Servers_List(ByVal lstOut As IList)
Dim rss As RegisteredServers.RegisteredServerCollection = SmoApplication.SqlServerRegistrations.RegisteredServers
Dim rse() As RegisteredServers.RegisteredServer = SmoApplication.SqlServerRegistrations.EnumRegisteredServers
Dim rsgs As RegisteredServers.ServerGroupCollection = SmoApplication.SqlServerRegistrations.ServerGroups
Dim sg As New RegisteredServers.ServerGroup("AutoRegistered")
If Not rsgs.Contains("AutoRegistered") Then
sg.Create()
Else
sg = rsgs.Item("AutoRegistered")
End If
lstOut.Clear()
For Each rs As RegisteredServers.RegisteredServer In rse
lstOut.Add(rs.Name.ToUpper)
Next
Dim dt As DataTable = SmoApplication.EnumAvailableSqlServers(False)
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
If Not lstOut.Contains((dr!Name).ToString.ToUpper) Then
lstOut.Add(dr!Name.ToString.ToUpper)
Dim rs As New RegisteredServers.RegisteredServer(sg, dr!Name)
rs.ServerInstance = dr!Name
rs.Create()
End If
Next
End If
End Sub
End Module
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
March 21, 2008 at 9:34 am
Still don't see where the subnet comes to play. I want to query a different subnet than the one the app is running on.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply