Dapper "Handshake" 数据库错误

Dapper "Handshake" Database error

我正在使用 Dapper 从 table:

中查询和获取 ID 值列表
Dim systemIDs As IEnumerable(Of Long) = Nothing

Dim connString As String = GetMyConnectionString()
Using connection As New SqlConnection(connString)
    systemIDs = connection.Query(Of Long)("SELECT systemIDs FROM dbo.mySystems").ToList()
End Using

Query() 调用出错:

"Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=6; handshake=629;"

我用谷歌搜索了这个错误,但没有找到与 Dapper 有关的太多信息。有任何想法吗?我认为我查询的方式是正确的,但我是否遗漏了什么?

请注意,发生此错误时,如果我恢复,则它似乎可以重试并正常连接。我只注意到这个错误,因为我在调试时遇到了异常。它只发生在第一个数据库连接上,所有其他对 .Query() 的后续调用都没有异常。我想知道 Dapper 背后发生了什么,因为在我尝试 Dapper 之前我一直在做常规 ADO.NET 查询,然后我没有注意到这个错误。

Dapper 在这里没有做任何出色的事情。我假设您的 connection 尚未打开 - 在这种情况下,dapper 会在需要时调用 Open(),并且大概是在它出错的时候。但是:错误本身与 dapper 没有任何关系。它 字面上 只是在这里调用 Open(或者 OpenAsync,如果你使用 async API)。我强烈怀疑如果将 Open() 移动到您自己的代码中,您会得到完全相同的行为。

"This issue can be resolved by modifying the connection string to set the parameter ‘TransparentNetworkIPResolution’ to false"

从这里开始:

https://blogs.msdn.microsoft.com/dataaccesstechnologies/2016/05/07/connection-timeout-issue-with-net-framework-4-6-1-transparentnetworkipresolution/