I have a problem connecting to SQL Server. I have already tried to check my other codes and resources on the web but it's not working.
JDBC Code
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://IP_ADD;databaseName=DB_NAME", "MY_USER", "MY_PASS");
Error Log
Error during process run: The TCP/IP connection to the host IP_ADDRESS, port
1433 has failed. Error: "connect timed out. 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 IP_ADDRESS, port 1433 has failed.
Error: "connect timed out. 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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at LoadTextFile.main(LoadTextFile.java:40)
Wai Ha Lee
8,856102 gold badges61 silver badges100 bronze badges
asked May 27, 2015 at 14:52
dimas
2,6076 gold badges43 silver badges67 bronze badges
1 Answer 1
It's clear in the error:
The TCP/IP connection to the host IP_ADDRESS, port 1433 has failed.
It seems you are using a IP_ADDRESS constant for the server. Make sure the IP_ADDRESS has right host name, (or) replace it with actual server name/IP address in the database URL.
Wai Ha Lee
8,856102 gold badges61 silver badges100 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
dimas
I replaced the real ip address with IP_ADDRESS for security purposes
K139
@dimas then make sure the actual values are correct, and there is an instance of sql server running. It seems either sql server is down (or) the values you are using in code are not correct.
FlipperPA
Are you sure you can connect to your IP address from the server connecting? A simple test is to go to command line, and try: "telnet IP_ADDRESS 1433" If it connects, then your problem is elsewhere. If it hanging on "Connecting To IP_ADDRESS..." then the problem may be firewall related.
Gord Thompson
@dimas - Also be aware that the Express editions of SQL Server do not listen on port 1433 (and have TCP/IP connections disabled by default if I remember correctly).
default
DB_NAME,MY_USERandMY_PASSWORDare just example credentials. You need to set up your own server and supply the appropriate database name, username and password in order to connect.