Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
Private Sub cboSvrName_DropDown(ByVal sender As Object, _
                                    ByVal e As System.EventArgs) _
                                    Handles cboSvrName.DropDown
        'List all servers both local and non-local
        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.
VB
Private Sub cboSvrName_SelectedIndexChanged(ByVal sender As Object, _
                                               ByVal e As System.EventArgs) _
                                               Handles _
                                               cboSvrName.SelectedIndexChanged
       'Cursor.Current = Cursors.WaitCursor
       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
       'Cursor.Current = Cursors.Default
   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
Posted

1 solution

This error tells you that you need to establish connection to selected MS SQL server before you start retrieving database names. As you probably know, SQL Server Database Engine is set to either Windows Authentication mode or SQL Server and Windows Authentication mode. Before you connect, you need to know which mode of authentication is used on selected server. First try to connect to sql server using windows authentication, if it fails (return error), call custom window with database user login and password (you need to create it).
More about connection string: http://www.connectionstrings.com/[^]
 
Share this answer
 
Comments
MRM256 13-Apr-13 9:50am    
I've looked at the www.connectionstrings.com website at the connection strings used for SQL Server 2005. Every string I looked at needed a server name, Initial catalog(database), and other items like user name & password or trusted connection. This is where I'm confused: I want to connect to the non-local server so I can look at the databases available on the selected PC. For example: I selected the SQL Server Express located on my Win XP PC. Since the application is running on my Win 8 machine and the server I want to see databases on is on the Win XP machine I need to connect to the Server on the Win XP system. The question is: How is that done when the only data I have at this point is the name of the Server, and I've set the Authentication method to Trusted connection?
RedDk 14-Apr-13 14:25pm    
When I type the words "antivirus software" into the search of this page mentioned here I get "zero returns". When I start up SQL Server 2008 I'm prompted to select an instance from a dropdown list. I usually pick one of the ones which is running on this computer. One that'll show up as a Service in Computer Management. BUT ... there are others in this dropdown list. One's that I have given administrative rights to run through BOTH my antivirus software (big tell ... when the instance on the remote computer is prompted to start it has to be ok with antivirus so a screen pops up compliments of the antivirus program) AND the Permissions on the local caller. First things first then. Can one drag and drop files from the remote box to the local box?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900