Java 到主机 localhost 的 TCP/IP 连接,端口 1433 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18981279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:02:44  来源:igfitidea点击:

The TCP/IP connection to the host localhost, port 1433 has failed

javasql-servereclipsejdbc

提问by Navin Kumar

I'm getting this 2 errors repeatedly when I'm trying to connect eclipse with sql serverthrough jdbc. Could anyone help me with this or explain why am I getting this?

当我尝试通过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.

Thank you.

谢谢你。

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);

回答by sunysen

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

When it opens Go to

当它打开时转到

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

Where you'll find the Protocol TCP/IP, if disabled then Enable it Click on TCP/IP, You'll find its properties.

在哪里可以找到协议 TCP/IP,如果禁用,则启用它 单击 TCP/IP,您将找到它的属性。

In this properties Remove All the TCP Dynamic Ports and Add value of 1433 to all TCP Port and restart your SQL Server Services > SQL Server

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

And Its Done...

它完成了......

回答by Raman B

For this kind of issue - you can resolve by checking whether all sql server related services are running or not.

对于此类问题 - 您可以通过检查所有与 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

Start all the above services. and set to start up type to Automatic.

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

SQL Active Directory Helper Service is not required to keep running.

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

It can used to deal with error SQL server connection error 2 and with he TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused:

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

回答by Steven Rodriguez

If you are running SQLSERVER EXPRESS:

如果您正在运行 SQLSERVER EXPRESS:

Use "SQL Server Configuration Manager" or write "mmc.exe" on Win+R and search "SQL Server Network Configuration", in the "Protocols for SQLEXPRESS" enable the option TCP/IP

使用“SQL Server 配置管理器”或在 Win+R 上编写“mmc.exe”并搜索“SQL Server 网络配置”,在“SQLEXPRESS 的协议”中启用 TCP/IP 选项

I hope than this works for somebody!!

我希望这对某人有用!!