如何提取SQL服务器组中的可用SQL服务器列表?我打算把这个列表放在VB.NET的组合框中.
我知道这样做的唯一方法是使用命令行:
osql -L
但是我发现下面的文章似乎解决了填充组合框的具体目标:
http://www.sqldbatips.com/showarticle.asp?ID=45
如果你不想被绑定到SQL SMO,这是Ben的文章使用的,你可以做这样的事情来发现网络上的所有SQL服务器:
Private Sub cmbServer_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbServer.DropDown
Dim oTable As Data.DataTable
Dim lstServers As List(Of String)
Try
If cmbServer.Items.Count = 0 Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
oTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources
For Each oRow As DataRow In oTable.Rows
If oRow("InstanceName").ToString = "" Then
cmbServer.Items.Add(oRow("ServerName"))
Else
cmbServer.Items.Add(oRow("ServerName").ToString & "\" & oRow("InstanceName").ToString)
End If
Next oRow
End If
Catch ex As Exception
ErrHandler("frmLogin", "cmbServer_DropDown", ex.Source, ex.Message, Ex.InnerException)
Finally
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
If oTable IsNot Nothing Then
oTable.Dispose()
End If
End Try
End Sub
该SqlDataSourceEnumerator类是不错的,因为它可以让你的SQL服务器发现右出的2.0框架.