到主机本地主机,端口1433的TCP/IP连接失败错误,需要帮助 [英] The TCP/IP connection to the host localhost, port 1433 has failed error, need assistance

查看:83
本文介绍了到主机本地主机,端口1433的TCP/IP连接失败错误,需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的完全错误:

与主机localhost(端口1433)的TCP/IP连接失败.错误:连接超时.请验证连接属性.请确保主机上正在运行SQL Server实例并在端口上接受TCP/IP连接.请确保防火墙未阻止与端口的TCP连接..

The TCP/IP connection to the host localhost, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

我已经使用端口1433检查是否已启用TCP/IP,并且TCP动态端口为空.我已禁用Windows防火墙.

I have already checked that TCP/IP is enabled, using port 1433, and TCP dynamic ports is empty. I have disabled windows firewall.

这是我的代码:

import java.sql.*;

public class DBConnect {




public static void main(String[] args) {
    // TODO Auto-generated method stub

    String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=TestDB1;instance=SQLSERVER;encrypt=true;TrustServerCertificate=true;";
    String user = "sa";
    String pass = "";
    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");


    Connection myConn = DriverManager.getConnection(dbURL, user, pass);
    try {
    Statement myStmt = myConn.createStatement();

    try {
    ResultSet myRs = myStmt.executeQuery("Select * from Login");



        while (myRs.next())
        {
            System.out.println(myRs.getString("Username"));
            System.out.println(myRs.getString("Password"));
        }
    }
    catch (Exception e)
    {
        System.out.println("Error with query");
    }
    }

    catch (Exception e)
    {
        System.out.println("Error connecting to database");
    }
    }

    catch (Exception e)
    {
        System.out.println(e);
    }
}

}

推荐答案

您是否启用了命名管道"和"TCP/IP"?

  1. 打开"Sql Server配置"应用程序.

  1. Open the 'Sql Server Configuration' application.

在左窗格中,转到"SQL Server网络配置"->"[实例名称]的协议"

In the left pane, go to 'SQL Server Network Configuration' -> 'Protocols for [instance-name]'

右键单击命名管道"和"TCP/IP",然后选择启用".

Right-click on both 'Named Pipes' and 'TCP/IP' and select 'enable'.

您使用了正确的端口吗?

  1. 双击"TCP/IP"

  1. Double-click on 'TCP/IP'

选择"IP地址"标签

滚动到IPAII.您的端口号在这里.

Scroll to IPAII. Your port number is here.


  1. 重新启动"SQL Server([instance-name])" Windows服务.

这篇关于到主机本地主机,端口1433的TCP/IP连接失败错误,需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆