我正在尝试使用Microsoft。数据SqlClient,但无法使连接正常工作。但是,当我使用该系统时。数据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(在Prem上(
- Prod-Ms 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";到连接字符串的末尾可以解决该问题。