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?