解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]

>>> 近期更新idea版本到2022.2.3后, 使用idea自带的数据库管理工具连接SQLServer2014数据库时出现问题:

```

[08S01] 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。

错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]”。 ClientConnectionId:ac252ff7-8620-437d-b217-2c03c556ffff

The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]

```

>>> 连续两天, 搜索了无数的文章亲测无效, 几近放弃...

    然后在 Stack Overflow 搜了下, 找到这么一个答案:  

```

---

Q:

    I upgraded DataGrip to 2021.1.2, and now when I run any query I get this response

    javax.net.ssl.SSLHandshakeException: The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]

    How to resolve this?

---

A:

    you need to do the following:

    1: create a new file (any where) with the name custom.java.security

    2: put the following content in the file

    jdk.tls.disabledAlgorithms=SSLv3, TLSv1.1, RC4, DES, MD5withRSA, \

        DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \

        include jdk.disabled.namedCurves

    3 : open DataGrip -> in your database panel -> select the database you want -> right click -> select Properties -> go to the Advanced tab

    4 : in the VM Options field write the following

    -Djava.security.properties=${PATH_TO_FILE}/custom.java.security

    you need to replace ${PATH_TO_FILE} with the folder path of the file that you created in step 1

    don't forget to have \\ instead of one \ in path if you use windows

    5 : goto File menu -> select Invalidate Caches... -> click Invalidate And Restart

   

```

大致意思是:

1. 需要新建个文件, 建哪自己定, 名为: custom.java.security

2. 把以下内容写到这个文件中(记得别乱加空格):

```

jdk.tls.disabledAlgorithms=SSLv3, TLSv1.1, RC4, DES, MD5withRSA, \

        DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \

        include jdk.disabled.namedCurves

```

3. 点开idea中的 database 标签,

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第1张图片

选择你要设置的数据库软件的设置 (这里是 Microsoft SQL Server ), 找到 Advanced 标签页上的 VM Options 框 (!重要

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第2张图片

4. 框中填入 -Djava.security.properties=${PATH_TO_FILE}/custom.java.security ,

    记得把 ${PATH_TO_FILE} 替换成第一步中的 custom.java.security 所在的文件夹路径, 路径可以直接去地址栏复制, 记得复制完把"\"全改为"\\",

    这里打个样:

-Djava.security.properties=D:\\Program Files\\QQ/custom.java.security

    哦对了, 我的jdbc用的是8.2.2 , 在这里查看和设置, 至于是否跟解决此问题有关就不清楚了, 请各位自行尝试

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第3张图片

    填完别忘了点 ok

5. 最后 idea 左上角菜单 File ->  Invalidate Caches... ->  Invalidate And Restart

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第4张图片解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第5张图片

OK, enjoy

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第6张图片

最后, 感谢这位 Ali Faris 大佬

解决报错:The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]_第7张图片

你可能感兴趣的:(SQLServer,microsoft,sqlserver,intellij,idea)