在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
发布于 2019-07-12 03:16:00
为了让它第一次连接,看起来我需要添加"Network Library=DBMSSOCN;“来在调试中连接。不知道为什么..。
发布于 2019-07-12 02:19:15
看起来您的本地连接没有默认使用命名管道,但是您的编译版本将尝试(或允许使用TCP/IP)。该错误表明它可能需要命名管道。
尝试将此"np:“放入数据源中的连接字符串中:
Data Source=np:xx.xx.xx.xx; ...
https://stackoverflow.com/questions/56994102
复制相似问题