无法连接到服务器MRM-DT-002 \ SQLEXPRESS [英] Failed to connect to server MRM-DT-002\SQLEXPRESS
问题描述
我有两台电脑。我的Windows 8系统是我正在编写应用程序的地方。 Windows 8机器上也是SQL Server的本地实例。我的另一台PC正在运行Windows XP,它上面有一个SQL Server Express实例。
我研究了互联网并想出了这个代码来列出每个实例网络上的SQL Server。
私有 Sub cboSvrName_DropDown( ByVal sender 作为 对象 ,_
ByVal e As System.EventArgs)_
句柄 cboSvrName.DropDown
' 列出本地和非本地服务器-local
Dim dt = SmoApplication.EnumAvailableSqlServers( False )
Cursor.Current = Cursors.WaitCursor
cboSvrName.ValueMember = 名称
cboSvrName.DataSource = dt
Cursor.Current = Cursors。默认
结束 Sub
这很好用。它在我的两台PC上调用SQL Server的实例。但是,当我选择我的Win XP PC的SQL Server Express实例时,我希望此代码在所选PC的SQL Server Express实例上的所有SQL数据库中列出另一个组合框。
< pre lang =vb> 私有 Sub cboSvrName_SelectedIndexChanged( ByVal 发件人作为 对象,_
ByVal e As System.EventArgs)_
句柄 _
cboSvrName.SelectedIndexChanged
' Cursor.Current = Cursors.WaitCursor
如果 cboSvrName.SelectedIndex<> -1 然后
Dim serverName As 字符串 = cboSvrName.SelectedValue.ToString()
Dim 服务器作为服务器= 新服务器(serverName)
尝试
对于 每个数据库作为数据库在 server.Databases
cboDB.Items.Add(database.Name)
Next
Catch ex As 例外
Dim 例外作为 S tring = ex.Message
MessageBox.Show(exception)
End 试试
结束 如果
' Cursor.Current = Cursors.Default
结束 Sub
这是我出现问题的地方:我在大约30秒后选择服务器名称(连接失败超时)我收到此消息:无法连接到服务器MRM-DT-002 \ SQLEXPRESS。
显然我必须首先建立与此连接SQL Server Express的非本地实例,然后才能从中获取任何信息,我不知道该怎么做。我看到的每个连接字符串都假定程序员将知道他需要哪个SQL Server和哪个数据库。在我的应用程序中,我试图让用户可以选择。
有谁知道如何建立与非本地SQL服务器的连接,以便我可以检索到的名称它的数据库?
提前致谢,
MRM256
此错误告诉您在开始检索数据库名称之前需要建立与所选MS SQL服务器的连接。您可能知道,SQL Server数据库引擎设置为Windows身份验证模式或SQL Server和Windows身份验证模式。在连接之前,您需要知道在所选服务器上使用哪种身份验证模式。首先尝试使用Windows身份验证连接到sql server,如果失败(返回错误),请使用数据库用户登录名和密码调用自定义窗口(需要创建它)。
有关连接字符串的更多信息:< a href =http://www.connectionstrings.com/> http://www.connectionstrings.com/ [ ^ ]
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
'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.
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
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/[^]
这篇关于无法连接到服务器MRM-DT-002 \ SQLEXPRESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!