驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not ...

驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”

虽然现在大家基本上都用mysql数据库了,但是难免有时候会碰到要使用sqlserver的情况。

这时候如果你不是用微软的产品去连接,比如你用java开发,使用驱动包连接可能会碰到【驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”】这个错误.

低版本的驱动还可能是英文的报错【The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS12]". ClientConnectionId:d5fd8d69-ae88-4055-9f6d-6e8515224ce2】。

这个问题其实最主要还得看后面那一句话【The server selected protocol version TLS10 is not accepted by client preferences [TLS12]】,意思是数据库服务端的协议版本是TLS10,而客户端协议版本是TLS12。

只需要在你的设备上找到jdk的安装目录【\Java\jdk1.8.0_291\jre\lib\security】下的java.security改改安全协议的配置即可。删掉这两个:TLSv1、TLSv1.1。特别要注意的是,如果你是选择了jre的运行环境来运行,那就是这个目录【\jre1.8.0_291\lib】

修改前:
jdk1.png

修改后:

jdk2.png

附上springboot 连接sql server的配置代码
1、引入依赖

<dependency>
       <groupId>com.microsoft.sqlserver</groupId>
       <artifactId>mssql-jdbc</artifactId>
       <version>8.2.2.jre8</version>
</dependency>

2、数据库连接配置

driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://ip:port;databasename=数据库名
username: sa
password: 密码

分享到这里就结束了,欢迎大家讨论指正。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容