如何提取SQL服務器組中可用SQL服務器的列表?我打算把這個列表放在VB.NET的組合框中。獲取SQL服務器組中可用服務器的列表
3
A
回答
5
我知道這是使用命令行做的唯一方法:
osql -L
但我發現下面的文章,這似乎解決您的具體目標填充組合框:
0
在C#中我使用過調用odbc32.dll
例如:
[DllImport("odbc32.dll", CharSet = CharSet.Ansi)]
private static extern short SQLBrowseConnect(
IntPtr hconn, StringBuilder inString,
short inStringLength, StringBuilder outString, short outStringLength, out short
outLengthNeeded);
文檔該功能是MSDN
5
如果你不想被捆綁到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框架。
相關問題
- 1. 獲取網絡SQL服務器列表
- 2. 從sql表列中的服務器路徑獲取服務器名稱
- 3. Powershell獲取服務器列表,並添加「服務器」屬性
- 4. SQL服務器列表
- 5. SQL服務器列表
- 6. SQL服務器獲得父列表
- 7. 獲取一組服務器的LocalAdmins服務器
- 8. 獲取服務器列表的特定服務恢復選項
- 9. 表中的SQL服務器
- 10. 獲取Windows Azure服務器中的SQL Azure數據庫列表
- 11. SQL Select基於可用服務器/表
- 12. NULLABLE列上的SQL服務器分組
- 13. SQL服務器,獲取產值sp_executesql的
- 14. 如何獲取SQL服務器觸發器中已更新列的列表?
- 15. 從服務器B讀取/獲取服務器A的Cookie
- 16. SQL服務器 - 從一組
- 17. SQL服務器:鏈接服務器沒有鏈接服務器?
- 18. SQL服務器
- 19. SQL服務器
- 20. SQL服務器
- 21. SQL服務器
- 22. - SQL服務器
- 23. SQL服務器
- 24. SQL服務器
- 25. SQL服務器
- 26. SQL(服務器):
- 27. SQL服務器:與外鍵的列表
- 28. 針對服務器組的SQl服務器查詢
- 29. SQL服務器分組列值
- 30. 在MySQL服務器中鏈接MS SQL服務器表
該文章似乎不再工作:( – mrc 2016-05-09 08:48:33