Files
workspace/notes/后端开发/数据库/sqlserver/sqlserver遇到的各种错误.md
T
2025-10-15 22:26:50 +08:00

76 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Java 连接 SQL Server 报错 TLS10
## 问题描述
在使用 **Java 8** 连接 **SQL Server 2008** 或老版本时,出现报错:
```
The server selected protocol version TLS10 is not accepted by client preferences [TLS12]
```
**原因**:
- SQL Server 2008 只支持 **TLS 1.0**
- Java 8 默认禁用 TLS 1.0/1.1(从某个更新版本起)
- 导致 SSL/TLS 握手失败
------
## 解决方案
### 方法 1:修改 `java.security` 配置文件
1. 打开文件:
```
<JDK_HOME>\jre\lib\security\java.security
```
1. 找到以下行:
```
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, 3DES_EDE_CBC, ...
```
1. 删除 `TLSv1`、`TLSv1.1`,修改为:
```
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, anon, NULL, \
include jdk.disabled.namedCurves
```
> ✅ 这样 JVM 启动后会允许 TLS 1.0,从而兼容 SQL Server 2008。
------
### 方法 2:在 JVM 启动参数中启用 TLS1.0(无需改文件)
```
-Djdk.tls.client.protocols=TLSv1,TLSv1.1,TLSv1.2
```
**用法示例**:
- IDEA VM options:
```
-Dfile.encoding=UTF-8 -Djdk.tls.client.protocols=TLSv1,TLSv1.1,TLSv1.2
```
- 命令行启动:
```
java -Djdk.tls.client.protocols=TLSv1,TLSv1.1,TLSv1.2 -jar yourapp.jar
```
# Navicat 连接 SQL Server 常见报错及解决方案
针对 Navicat 连接 SQL Server 2008/2008 R2 时可能出现的不同错误,整理成“错误 → 原因 → 解决”对照表,方便快速定位。
| 错误信息 | 原因 | 解决方案 |
| ------------------------------------------------------------ | ----------------------------------------- | ------------------------------------------------------------ |
| `[08001] [ODBC Driver 17 for SQL Server] SQL Server Network Interfaces: Connection string is not valid [87]` | 驱动不兼容老版本 SQL Server,连接格式不对 | 用 **Native Client 10.0** 驱动,填写正确服务器、端口、账号、数据库 |
| `[08001] [Microsoft][SQL Server Native Client 10.0] SQL Server 网络接口: 连接字符串无效 [87]` | 服务器不可达或连接格式错误 | 地址格式应 `192.168.1.100,1433`(逗号分隔),确保 TCP/IP 启用,端口开放 |