驅(qū)動程序無法通過使用安全套接字層(SSL)加密與 SQL Server 建立安全連接。錯誤:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”
雖然現(xiàn)在大家基本上都用mysql數(shù)據(jù)庫了,但是難免有時候會碰到要使用sqlserver的情況。
這時候如果你不是用微軟的產(chǎn)品去連接,比如你用java開發(fā),使用驅(qū)動包連接可能會碰到【驅(qū)動程序無法通過使用安全套接字層(SSL)加密與 SQL Server 建立安全連接。錯誤:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”】這個錯誤.
低版本的驅(qū)動還可能是英文的報錯【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]】,意思是數(shù)據(jù)庫服務(wù)端的協(xié)議版本是TLS10,而客戶端協(xié)議版本是TLS12。
只需要在你的設(shè)備上找到j(luò)dk的安裝目錄【\Java\jdk1.8.0_291\jre\lib\security】下的java.security改改安全協(xié)議的配置即可。刪掉這兩個:TLSv1、TLSv1.1。特別要注意的是,如果你是選擇了jre的運行環(huán)境來運行,那就是這個目錄【\jre1.8.0_291\lib】。
修改前:
修改后:

附上springboot 連接sql server的配置代碼
1、引入依賴
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.2.2.jre8</version>
</dependency>
2、數(shù)據(jù)庫連接配置
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://ip:port;databasename=數(shù)據(jù)庫名
username: sa
password: 密碼
分享到這里就結(jié)束了,歡迎大家討論指正。