【发布时间】:2019-07-11 16:58:25
【问题描述】:
在 SQL 中调试时,出现以下异常:-
System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
当我设置下一条语句并再次运行该语句时,它就可以工作了。当我将应用程序作为已编译的应用程序独立运行时,它也可以工作。任何人都知道为什么只有在调试时才会导致错误。
连接到位于异地的远程数据库,而不是本地数据库。
Data Source=xx.xx.xx.xx;Initial Catalog=TheDatabase;User ID=MasterUser;Password=AsIfIMGoingToPostThat
感谢您的帮助。
这是我的连接功能...
Public Sub New(ByVal strConnect As String)
Try
dbConnect = New System.Data.SqlClient.SqlConnection(strConnect)
dbConnect.Open()
objParams = New List(Of SqlClient.SqlParameter)
m_bIsConnected = True
Catch exc As Exception
m_bIsConnected = False
Finally
End Try
【问题讨论】: