Devdit
 

TCP/IP connection to the host port 1433 has failed วิธีแก้ไข

1K

ต้องการเชื่อมต่อฐานข้อมูล SQL Server 2019 Express ด้วยภาษา Java โดยใช้ JDBC แต่รันแล้วขึ้น Error ว่า The TCP/IP connection to the host EXPRESSS\SQLEXPRESS, 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." ปัญหานี้แก้ไขอย่างไร

package net.codejava.jdbc;

class Test {  
    public static void main(String args[]){ 
        Connection conn = null;
        try {
            String connURL =    "jdbc:sqlserver://EXPRESS\\SQLEXPRESS;"+
                                "databaseName=demo;"+
                                "integratedSecurity=true;"+
                                "portNumber=1433;";
            conn = DriverManager.getConnection(connURL);
            if (conn != null) {
                System.out.println("Java เชื่อมต่อ SQL Server Express");
            }            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}

 

วิธีแก้ไข

เบื้องต้นแนะนำให้ลอง enabled การติดต่อสื่อสารของ TCP/IP ก่อน และกำหนด IP Addresses ในส่วนของ IPAll เป็น 1433 ที่โปรแกรม Sql Server Configuration Manager โดยมีรายละเอียดดังนี้

1. เปิดโปรแกรม Sql Server Configuration Manager คลิก SQL Server Network Configuration > เลือก Protocols for SQLEXPRESS และ คลิกขวาที่ TCP/IP เลือก Enabled

 

2. คลิกขวาที่ TCP/IP เลือก Properties > เลือก IP Addresses เลื่อนลงมาด้านล่างสุดตรง IPAll กำหนด TCP Port เป็น 1433 และกด OK

3. Restart Service SQL Server ที่หน้าโปรแกรม Sql Server Configuration Manager เลือก SQL Servers Service จากนั้นคลิกขวาที่ SQL Service และเลือกเมนู Restart

แก้ไข 1 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ