29

当我尝试通过jdbc将 eclipse 与sql server连接时,我反复收到这 2 个错误。谁能帮我解决这个问题或解释我为什么会得到这个?

1. The TCP/IP connection to the host localhost, port 1433 has failed.  
2. The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.

谢谢你。

String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driver).newInstance();
String connString      ="jdbc:sqlserver://localhost:1433/databaseName=Engg_Street;instance=SQLSERVER;encrypt=true;     trustServerCertificate=true";
String username = "Vijayalakshmi";
String password = "";
conn = DriverManager.getConnection(connString,username,password);
4

3 回答 3

56
You need to Go to Start > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager

打开时转到

SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for SQLExpress 

你会在哪里找到协议 TCP/IP,如果禁用然后启用它点击 TCP/IP,你会找到它的属性。

在此属性中删除所有 TCP 动态端口并将值 1433 添加到所有 TCP 端口并重新启动您的 SQL Server 服务 > SQL Server

它完成了......

于 2013-09-24T12:30:08.143 回答
2

如果您正在运行 SQLSERVER EXPRESS:

使用“SQL Server 配置管理器”或在 Win+R 上编写“mmc.exe”并搜索“SQL Server Network Configuration”,在“Protocols for SQLEXPRESS”中启用选项 TCP/IP

我希望这对某人有用!

于 2020-03-21T21:55:54.603 回答
1

对于此类问题 - 您可以通过检查所有 sql server 相关服务是否正在运行来解决。

TO check Start -> Run -> services.msc 
check services related to sql as
SQL Server (MSSQLSERVER)
SQL Server Agent (MSSQLSERVER)
SQL Server Analysis Services (MSSQLSERVER)
SQL Server Browser
SQL Server Integration Services 10.0
SQL Server Reporting Services (MSSQLSERVER)
SQL Server VSS Writer

启动上述所有服务。并将启动类型设置为自动。

SQL Active Directory Helper Service 不需要保持运行。

它可用于处理错误 SQL 服务器连接错误 2 以及与主机 localhost 的 TCP/IP 连接,端口 1433 失败。错误:“连接被拒绝:

于 2016-05-20T06:04:17.657 回答