Microsoft.Data.SqlClient - 登录前握手错误
Microsoft.Data.SqlClient - Error pre-login handshake
我正在尝试使用 Microsoft.Data.SqlClient 但无法建立连接。但是,当我使用 System.Data.SqlClient 时一切正常。
try
{
using (var connection = new SC.SqlConnection(connectionString))
{
connection.Open();
connection.State.ShouldBe(ConnectionState.Open);
}
}
catch (Exception e)
{
throw;
}
连接字符串是:
"server=[[**SERVER_NAME**]];Trusted_Connection=True;database=[[**DATABASE**]];min pool size=0;max pool size=100;Application Name=Data.Tests.DotNet;timeout=120"
我得到的错误是:
Microsoft.Data.SqlClient.SqlException
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )
我能找到的所有内容都会在 'error: 0 -' 之后显示一些消息。
有人能帮忙吗?
更新
公司的环境是:
- Dev/UAT - Ms Sql Server 2012 Enterprise(本地)
- Prod - 女士 Sql Server 2016 Azure(云)
连接字符串:
- 开发/UAT:
"server=[[**SERVER_NAME**]];Trusted_Connection=True;database=[[**DATABASE**]];min pool size=0;max pool size=100;Application Name=Data.Tests.DotNet;timeout=120"
- 生产:
"Server=tcp:[[**SERVER_NAME]],1433;database=[[**DATABASE**]];Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication='Active Directory Integrated';Application Name=Data.Tests.DotNet;"
在连接字符串末尾添加“TrustServerCertificate=true”可能会解决问题。
我正在尝试使用 Microsoft.Data.SqlClient 但无法建立连接。但是,当我使用 System.Data.SqlClient 时一切正常。
try
{
using (var connection = new SC.SqlConnection(connectionString))
{
connection.Open();
connection.State.ShouldBe(ConnectionState.Open);
}
}
catch (Exception e)
{
throw;
}
连接字符串是:
"server=[[**SERVER_NAME**]];Trusted_Connection=True;database=[[**DATABASE**]];min pool size=0;max pool size=100;Application Name=Data.Tests.DotNet;timeout=120"
我得到的错误是:
Microsoft.Data.SqlClient.SqlException
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )
我能找到的所有内容都会在 'error: 0 -' 之后显示一些消息。
有人能帮忙吗?
更新
公司的环境是:
- Dev/UAT - Ms Sql Server 2012 Enterprise(本地)
- Prod - 女士 Sql Server 2016 Azure(云)
连接字符串:
- 开发/UAT:
"server=[[**SERVER_NAME**]];Trusted_Connection=True;database=[[**DATABASE**]];min pool size=0;max pool size=100;Application Name=Data.Tests.DotNet;timeout=120"
- 生产:
"Server=tcp:[[**SERVER_NAME]],1433;database=[[**DATABASE**]];Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication='Active Directory Integrated';Application Name=Data.Tests.DotNet;"
在连接字符串末尾添加“TrustServerCertificate=true”可能会解决问题。