gpt4 book ai didi

c# - Microsoft.Data.SqlClient - 登录前握手错误

转载 作者:行者123 更新时间:2023-12-05 00:45:31 26 4
gpt4 key购买 nike

我正在尝试使用 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 - )

我能找到的所有内容都在“错误:0 -”之后显示一些消息。

谁能帮忙?

更新

公司的环境是:

  1. Dev/UAT - Ms Sql Server 2012 Enterprise(本地)
  2. 产品 - Ms Sql Server 2016 Azure(云)

连接字符串:

  1. 开发/UAT:
"server=[[**SERVER_NAME**]];Trusted_Connection=True;database=[[**DATABASE**]];min pool size=0;max pool size=100;Application Name=Data.Tests.DotNet;timeout=120"
  1. 制作:
"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”添加到连接字符串的末尾可能会解决问题。

关于c# - Microsoft.Data.SqlClient - 登录前握手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63274297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com