0

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)
3
  • DB_NAME, MY_USER and MY_PASSWORD are just example credentials. You need to set up your own server and supply the appropriate database name, username and password in order to connect. Commented May 27, 2015 at 14:58
  • what is more "jdbc:sqlserver://IP_ADD;databaseName=DB_NAME" seems to be wrong. I would suggest trying "jdbc:sqlserver://host:port/database" instead (replace each field with valid credentials) Commented May 27, 2015 at 14:59
  • Thanks Tinki i tried that it works but the problem is not with the syntax but a firewall problem. Commented May 28, 2015 at 4:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I replaced the real ip address with IP_ADDRESS for security purposes
@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.
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.
@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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.