0

so I am attempting to connect to a database on a network through java and I am having difficulty getting a connection to the server. I believe my problem is with the connection url. I have tried a few different things to test it out, but nothing has been working yet, so hopefully someone can help me. The error I get is:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.16, 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.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dbTest.db.dbConnect(db.java:23)
at dbTest.testConnection.main(testConnection.java:11)

Though depending on which connection url I use sometimes i get a java.net.sockettimeoutexception error. This is the code I am currently using to try to connect:

        try
    {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Properties props = new Properties();
        props.setProperty("user","sa");
        props.setProperty("password","");
        Connection conn = DriverManager.getConnection("jdbc:sqlserver://192.168.1.16;databaseName=ECCS",props);
        //MSSQL01\\ECLAIMS_DATA
        System.out.println("connected");            
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

The commented out MSSQL01\ECLAIMS_DATA is the name of the server and database I am attempting to connect to, I have tried using that as well. I'm just a little lost as to where everything needs to be. I have tried including the username and password in the connection string, I have tried using getConnection(url,username,password). I'm also not sure if the databaseName is where that needs to go. Can anyone help me out?

Compass
  • 5,867
  • 4
  • 30
  • 42
Tapialj
  • 333
  • 2
  • 3
  • 11
  • It looks like it might not be the URL, but rather the connection, are you sure your sql server is listening on that port? – Zachary Craig Oct 24 '14 at 16:40
  • I checked it out, and it was listening on a different port. I got that changed and now I am getting an erro that SQL Server 8 is not supported by the driver, so I will need to figure that out. I feel a little dumb now, didn't even think about the port. – Tapialj Oct 24 '14 at 16:52
  • what is SQL Server 8 by the way..? If you are referring to SQL server 2008 then you can use sqljdbc4.jar without any issues.. – Thirumalai Parthasarathi Oct 24 '14 at 16:59
  • We are running SQL server 2008 as far as I know, but the error keeps popping up. I solved it and got a connection by using JDBC version 3.0. Strange though that it wouldn't connect to 2008. – Tapialj Oct 24 '14 at 17:04

0 Answers0