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

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I am new to JDBC connections and I am very confused. I have enable TCP/IP and Named Pipes and in TCP/IP -> IP Adresses I have set TCP port to 1433 and I have restarted the server. I have also open access to SQL Server via Windows Firewall with Advanced Security. The problem is that I still get this error:

SQLException: The TCP/IP connection to the host MSSQL$SQLFULL, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."

I run on cmd the following: telnet SQLFULL 1433 and I get this message: Could not open connection to the host on port 1433 : connect failed

My code:

String url = "jdbc:sqlserver://MSSQL$SQLFULL:1433;databaseName=BA_ELTRUN;"; Connection dbcon = null; String errorMessages = "";  try {     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch(java.lang.ClassNotFoundException e) {     System.out.print("ClassNotFoundException: ");     System.out.println(e.getMessage()); }  try {     dbcon = DriverManager.getConnection(url,"username","password"); } catch(SQLException e) {      System.out.print("SQLException: ");      System.out.println(e.getMessage());      errorMessages = "Could not close connection with the Database Server: <br>"                     + e.getMessage();                     throw new SQLException(errorMessages); } 

Can anyone help?

回答1:

Copy computer name

cmd.exe -> hostname

or

Right Click on Start then click on System and copy the Computer Name

URL should be:

 String url = "jdbc:sqlserver://<Computer Name>\\SQLFULL:1433;databaseName=BA_ELTRUN;"; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!