SQL Server Pre-Login Handshake

二次信任 提交于 2019-12-04 02:32:28

According MSDN Doc .

ClearPool clears the connection pool that is associated with the connection.If additional connections associated with connection are in use at the time of the call, they are marked appropriately and are discarded (instead of being returned to the pool) when Close is called on them.

you should use ClearPool method before connection.close

refer : https://msdn.microsoft.com/zh-tw/library/system.data.sqlclient.sqlconnection.clearpool(v=vs.110).aspx

And If you use Using syntax to manage Object you should't use connection.close method

because it will call when they run to end . just open your connection and execute your command

 using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        SqlConnection.ClearPool(connection);
        /* my commands here */
        SqlCommand cmd = new SqlCommand("your command",conn);
        cmd.ExecuteReader()


    }

refer example : https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

last ensure SQL Server Network Config is right

What did the trick for me is increasing the timeout on the connection string, since when connecting by vpn it took to long to establish the connection. You can do this by adding ;connection timeout = value

I got the same error when connecting an application tried to connect to sql server while I was on a vpn.

By default the timeout is set to 15 seconds.

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!