调试并且无法打开与SQL的连接

时间:2019-07-11 16:58:25

标签: sql vb.net

在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

2 个答案:

答案 0 :(得分:0)

看起来您的本地连接没有默认使用命名管道,但是您的编译版本将尝试使用(或允许使用TCP / IP)。该错误表明它可能正在使用命名管道。

请尝试在连接字符串中的数据源中输入此“ np:”:

Data Source=np:xx.xx.xx.xx;  ...

答案 1 :(得分:0)

要使其首次连接,看来我需要添加“ Network Library = DBMSSOCN;”。连接调试。 t.b.h.,不知道为什么...