Hello,

I developed the code below to find all sql server on the network. Once the sql servers have been found display all the database that they have. The first part work. But the I can't get the servers to display their database. I have 3 sql servers, and they all display the databases on the local host, no matter which one I select.

Can anyone check my code below, thanks very much.

How can I put a test connected to database, so i know i have a connection established.

Many thanks in advance,

Code:
Private Sub ServerSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oSQLServer As New SQLDMO.SQLServer()
        Dim oServerList As SQLDMO.NameList
        Dim databases As SQLDMO.Databases
        Dim i As Integer

        'Finds a list off all the available servers on the network
        oServerList = oSQLServer.Application.ListAvailableSQLServers()

        'Populate the listbox with all the available servers
        Try
            For i = 1 To oServerList.Count
                lstServers.Items.Add(oServerList.Item(i)).ToString()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Connect by using trusted connection - windows authentication
        If (rdoTrustedConnection.Checked = True) Then
            oSQLServer.LoginSecure = True
            oSQLServer.Connect(lstServers.SelectedValue)
        ElseIf (rdoSQL.Checked = True) Then
            oSQLServer.Connect(lstServers.SelectedValue, txtUsername.Text, txtPassword.Text)
        End If

        'Get all the databases on this server and populate the list box
        databases = oSQLServer.Databases

        Try
            For i = 1 To databases.Count
                cboDatabases.Items.Add(databases.Item(i).Name)
            Next i
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

Steve