I have two PCs. My Windows 8 system is where I'm writing my application. Also on the Windows 8 machine is a local instance of SQL Server. My other PC is running Windows XP and it has an instance of SQL Server Express on it.
I researched the Internet and came up with this code to list every instance of SQL Server on the network.
Private Sub cboSvrName_DropDown(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles cboSvrName.DropDown
Dim dt = SmoApplication.EnumAvailableSqlServers(False)
Cursor.Current = Cursors.WaitCursor
cboSvrName.ValueMember = "Name"
cboSvrName.DataSource = dt
Cursor.Current = Cursors.Default
End Sub
This works just fine. It calls up the instances of SQL Server on both my PCs. However when I select my Win XP PC's instance of SQL Server Express I want this code to list into another combobox all SQL Databases on the selected PC's instance of SQL Server Express.
Private Sub cboSvrName_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles _
cboSvrName.SelectedIndexChanged
If cboSvrName.SelectedIndex <> -1 Then
Dim serverName As String = cboSvrName.SelectedValue.ToString()
Dim server As Server = New Server(serverName)
Try
For Each database As Database In server.Databases
cboDB.Items.Add(database.Name)
Next
Catch ex As Exception
Dim exception As String = ex.Message
MessageBox.Show(exception)
End Try
End If
End Sub
This is where my problem occurs: As soon as I select the server name after about 30 seconds(Connection failed timeout) I get this message: "Failed to connect to server MRM-DT-002\SQLEXPRESS."
Obviously I must first establish a connection to this non-local instance of SQL Server Express before I can get any information from it and I don't know how to do this. Every connection string I have seen assumes the programmer will know which SQL Server and which database he needs. In my application I trying to make them user selectable.
Does anyone know how to just establish a connection to a non-local SQL server so I can retrieve the names of the databases from it?
Thanks in advance,
MRM256