Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net6 程序 从 版本2.6.100升级到3.0.100 后无法连接 sqlserver 提示证书无效 #992

Closed
hzy-6 opened this issue Dec 30, 2021 · 7 comments

Comments

@hzy-6
Copy link
Collaborator

hzy-6 commented Dec 30, 2021

问题描述及重现步骤:

1640849064(1)

现在只有回退到 2.6.100

数据库的具体版本

sqlserver

安装的包

![image](https://user-images.githubusercontent.com/14025507/147730502-eed8c07a-397b-4e76-9452-44adc2ae3b01.png)

.net framework/. net core? 及具体版本

net6
@luoyunchong
Copy link
Collaborator

.NET 链接数据库:证书链是由不受信任的颁发机构颁发的

#967

@thtznet
Copy link

thtznet commented Jan 4, 2022

我已经踩坑了,在连接字符串里加入 “Encrypt=True; TrustServerCertificate=True;”

@weizhiyong05
Copy link

使用楼上的方法也不能解决
最后使用FreeSql.Provider.SqlServerForSystem替换FreeSql.Provider.SqlServer解决

@luoyunchong
Copy link
Collaborator

luoyunchong commented Jan 5, 2022

如果解决不了。直接new SqlConnection().Open()测试。。。与引用的上层ADO.NET驱动版本有关。

FreeSql.Provider.SqlServer在.netstandard2.0,.net 5.0,.net6.0时引用的是Microsoft.Data.SqlClient最新版是4.0.0.

参考 https://docs.microsoft.com/zh-cn/troubleshoot/sql/connect/error-message-when-you-connect

如果解决不了,就自行搜索相关问题。或按照楼上所说方法解决。

使用FreeSql.Provider.SqlServerForSystem替换FreeSql.Provider.SqlServer

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net60' or '$(TargetFramework)' == 'net50'">
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
</ItemGroup>

@weizhiyong05
Copy link

weizhiyong05 commented Jan 5, 2022

经过测试,总结经验如下,给有同样问题的网友参考,如有错误,请指正:
测试环境:windwos server2016、net6 .Net、Standard 2.1、sqlserver版本是2016

升级FreeSql和FreeSql.Provider.SqlServer时
Microsoft.Data.SqlClient会从3.0.1升级到4.0.0
仅仅是升级了FreeSql和FreeSql.Provider.SqlServer
然后就提示出错了,无法连接数据库:
会提示A connection was successfully established with the server, but then an error occurred during the login process.证书链是由不受信任的颁发机构颁发的

网友方法:
1.在连接字符串里加入 “Encrypt=True;TrustServerCertificate=True;”
2.在连接字符串里面加SslMode=none;
以上两种尝试之后发现不能解决问题


最后使用FreeSql.Provider.SqlServerForSystem替换FreeSql.Provider.SqlServer可以解决
请注意Microsoft.Data.SqlClient和System.Data.SqlClient的区别

FreeSql.Provider.SqlServer依赖项
.NETFramework Version=v4.0
FreeSql(>=3.0.100)

.NETFramework Version=v4.5
FreeSql(>=3.0.100)

.NETFramework Version=v4.5.1
FreeSql(>=3.0.100)
System.Data.SqlClient(>=4.8.3)

net5.0
FreeSql(>=3.0.100)
Microsoft.Data.SqlClient(>=4.0.0)

net6.0
FreeSql(>=3.0.100)
Microsoft.Data.SqlClient(>=4.0.0)

.NETStandard.Version=v2.0
FreeSql(>=3.0.100)
Microsoft.Data.SqlClient(>=4.0.0)


FreeSql.Provider.SqlServerForSystem依赖项
.NETFramework Version=v4.0
Freesql(>=3.0.100)

.NETFramework Version=v4.5
Freesql(>=3.0.100)

.NETFramework Version=v4.5.1
Freesql(>=3.0.100)
System.Data.SqlClient(>=4.8.3)

net5.0
Freesql(>=3.0.100)
System.Data.SqlClient(>=4.8.3)

net6.0
Freesql(>=3.0.100)
System.Data.SqlClient(>=4.8.3)

.NETStandard.Version=v2.0
Freesql(>=3.0.100)
System.Data.SqlClient(>=4.8.3)

有网友说使用证书,感兴趣的网友可以参考:
https://docs.microsoft.com/zh-cn/troubleshoot/sql/connect/error-message-when-you-connect

@xjj800211
Copy link

xjj800211 commented Jan 21, 2022

连接字符串增加Encrypt=False;也可以

@luoyunchong luoyunchong pinned this issue Mar 23, 2022
@changer0203
Copy link

楼上说的用方法使用后无效果,
最终加上这几个属性就好了
MultipleActiveResultSets=True;Encrypt=False;TrustServerCertificate=False;pooling=true;

@luoyunchong luoyunchong unpinned this issue May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants