2011-08-08 8 views
0

SQL Serverインスタンスを検索する次の機能があります。ローカルコンピュータで正常に動作します。この機能を使用してローカルエリアネットワーク上の他のコンピュータのインスタンスをチェックする方法を教えてください。私はVS 2008(.NET Framework 3.5)とSQL Server Express 2005を使用しています。LAN上の他のコンピュータでSQL Serverインスタンスを検索

Private Function MyInstanceFound(ByVal MyInstanceName As String) As Boolean 
    Dim InstanceFound As Boolean = False 
    Dim MC As ManagedComputer = New ManagedComputer() 
    For Each SI As ServerInstance In MC.ServerInstances 
     If SI.Name.ToString = MyInstanceName Then 
      InstanceFound = True 
      Exit For 
     End If 
    Next 
    Return InstanceFound 
End Function 

ありがとうございます。あなたはこの1つのように、別のManagedComputerコンストラクタを使用する必要が

よろしく、 SKPaul

+0

[ローカルネットワークにインストールされ、存在するSql Serverインスタンス(またはSqlExpress)のリストを取得する方法](http://stackoverflow.com/questions/5297021/how sql-server-instance-s-sqlexpress-that-are-installed-and-an-get-the-listを取得できます) –

答えて

0
Public Shared Function GetServerList(ByVal cmbServers As ComboBox) 
    Dim Server As String = String.Empty 
    Dim instance As Sql.SqlDataSourceEnumerator = Sql.SqlDataSourceEnumerator.Instance 
    Dim table As System.Data.DataTable = instance.GetDataSources() 
    For Each row As System.Data.DataRow In table.Rows 
     Server = String.Empty 
     Server = row("ServerName") 
     If row("InstanceName").ToString.Length > 0 Then 
      Server = Server & "\" & row("InstanceName") 
     End If 
     cmbServers.Items.Add(Server) 
    Next 
    cmbServers.SelectedIndex = cmbServers.FindStringExact(Environment.MachineName) 

End Function 

フォームでコンボボックス名txtservidoresを追加します。呼び出し関数 GetServerList(txtServidores)

関連する問題