com.microsoft.sqlserver.jdbc.SQLSe rverException: The TCP/IP connection to the host  has failed.
I am trying to connect to SQL Server 2005 Express with JDBC. I am getting the following exception: Code SnippetString connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=IFC3;"; // Declare the JDBC objects. Connection con = null; Statement stmt = null; ResultSet rs = null; try { // Establish the connection. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager.getConnection(connectionUrl,"ifc2","password"); com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at connectURL.main(connectURL.java:43)I am using the code example that came from Microsoft for making a JDBC connection. I looked at my configuration of SQL Server and change to use a static port 1433. I shut off Windows firewall to make sure it was not blocking communication. When I try to telnet to port 1433 it saysConnecting To 1433...Could not open connection to the host, on port 23: ConnectfailedAny suggestions?Thanks,Tom
May 21st, 2007 11:21am

Hi,Please enable the 1433 port, if you are using MSSQL 2005 server. By port for TCP/IP is configured to take dynamically, so make it to 1433. Now, how follow the below step.Microsoft SQL Server 2005 --> Configuration Tools --> SQL Server Configuration ManagerPart I (This will connect to your SQL EXPRESS)- Now, under it go to SQL Server 2005 Network Configuration-->Protocols for SQLEXPRESS.- Now, enable the VIA options by double click it.- Then, open TCP/IP part and set TCP Dynamic Ports: 1433 (or something else) under Protocal-->IP Address-->IP AllPart II (This will connect to your MS SQL Server)- Now, under it go to SQL Server 2005 Network Configuration-->Protocols for MSSQLSERVER.- Now, enable the VIA options by double click it.- Then, open TCP/IP part and set TCP Dynamic Ports: 1433 (or something else) under Protocal-->IP Address-->IP AllRegards,PortalAdmin
Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2008 2:57pm

Hi,I have done the below changes Microsoft SQL Server 2005 --> Configuration Tools --> SQL Server Configuration ManagerPart I (This will connect to your SQL EXPRESS)- Now, under it go to SQL Server 2005 Network Configuration-->Protocols for SQLEXPRESS.- Now, enable the VIA options by double click it.- Then, open TCP/IP part and set TCP Dynamic Ports: 1433 (or something else) under Protocal-->IP Address-->IP All Part II (This will connect to your MS SQL Server)- Now, under it go to SQL Server 2005 Network Configuration-->Protocols for MSSQLSERVER.- Now, enable the VIA options by double click it.- Then, open TCP/IP part and set TCP Dynamic Ports: 1433 (or something else) under Protocal-->IP Address-->IP AllBut still i am getting the exception:SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host JENESYS5/SQLEXPRESS, 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.".com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host JENESYS5/SQLEXPRESS, 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.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:207) at main.main(main.java:20)BUILD SUCCESSFUL (total time: 16 seconds)Could you please help me to resolve this issue.Thanks and Regards,V.Vithya
April 6th, 2009 12:44am

hi, i am facing the problem The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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.".so i tried to change my port number in configuration manager..but when i open it fails to open saying you do not premission or server is unreachable.....i thought there was a problem during installation...so i unistalled sql server and installed it again...but the error repeats...can any1 help me rectifying the problem..thanks,anusha
Free Windows Admin Tool Kit Click here and download it now
April 19th, 2009 8:21pm

I get exactly the same error: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host ROLAND/SQLEXPRESS, port 1471 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.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170) ....Strange thing is, I can connect with OSQL.Even stanger, I have a JDBC jndi installed under my app server, than can connect on the port. That is using exaclty the same JDBC driver.But under Hibernate, it gives this error.
June 2nd, 2009 12:12pm

jdbc:sqlserver://localhost\SQLEXPRESS/Databases/EPS:1357;user=epsingall;password=welkom1; Slashes/backslashes like this! Then my error was gone.
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2009 1:38pm

You are completely right... I just tried with this URL and it worked for me too!!! THANKS!!
August 24th, 2009 2:40pm

I was facing same problem. But after changing the configuration as mentioned, it is working for me. The connection URL when the server has a Instance is as follows: try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:sqlserver://127.0.0.1:1433; Instance=SQL2008;" + "databaseName=MB;user=sa;password=123;"; System.out.println("Successful"); Connection con = DriverManager.getConnection(connectionUrl); System.out.println("Successful"); } catch (SQLException e) { System.out.println("SQL Exception: "+ e.toString()); } catch (ClassNotFoundException cE) { System.out.println("Class Not Found Exception: "+ cE.toString()); } Thanks & Regards, M. Rabbi
Free Windows Admin Tool Kit Click here and download it now
December 12th, 2010 2:35am

Sorry guys. I follow this thread and I still have the same problem. I have SQL Server 2008 Instance=TRISTAN-PC DatabaseName=ClientData Port as usual=1433 User=sa password=123 I also made sure that i could get access to the database from outside this computer on the network using this User and Password and that worked. But the code doesn't work and tried many variant of your suggestions. Any one have an idea? And here is my code with my last try? // Create a variable for the connection string. String connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=ClientData;"; // Declare the JDBC objects. Connection con = null; Statement stmt = null; ResultSet rs = null; DataStructure dataIn; try { // Establish the connection. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //Global variable holding the connection LoadVariables.conDBPath = DriverManager.getConnection(connectionUrl,"sa","123"); //data model container dataIn = SQLTypePartner.selectType*Partner(); System.out.println(dataIn.toString()); } // Handle any errors that may have occurred. catch (Exception e) { e.printStackTrace(); } finally { dataIn = null; if (rs != null) try { rs.close(); } catch(Exception e) {} if (stmt != null) try { stmt.close(); } catch(Exception e) {} if (con != null) try { con.close(); } catch(Exception e) {} }//try
December 22nd, 2010 9:50pm

I found my problem, when I took a look at the config under SQL Native Client 10.0 Configuration, Client Protocols and TCP/IP, I saw Default port 1433 and I assume it was the real port no for the connection. I look further and Saw under SQL Server Network Configuration, Protocol for SQLServer and TCP/IP, the port number there was completely different (52477) I try that one and it work without a glitch? Thanks Guy this thread helped
Free Windows Admin Tool Kit Click here and download it now
December 23rd, 2010 9:23am

I found my problem, when I took a look at the config under SQL Native Client 10.0 Configuration, Client Protocols and TCP/IP, I saw Default port 1433 and I assume it was the real port no for the connection. I look further and Saw under SQL Server Network Configuration, Protocol for SQLServer and TCP/IP, the port number there was completely different (52477) I try that one and it work without a glitch? Thanks Guy this thread helped You are right. This was helpful for me too!!!!!
May 20th, 2011 10:44am

Thank u for the gr8 help. It worked for me.
Free Windows Admin Tool Kit Click here and download it now
June 6th, 2012 3:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics