I'm currently using the following connection string to connect to a database (the database is on the same server as the ServerIP):
String constr = "Data Source=ServerIP,1433;Network Library=DBMSSOCN;Initial
Catalog=dbName;User ID=dbUserID;Password=dbUserPassword";
This connects fine when used in asp.net. (I've manually created dbUserId and assigned it dbUserPassword from sql server management studio. dbUserId is the owner of the the database "dbName")
I have a java swing application on another pc, where i need to connect to the same database. I'm using sqljdbc4.jar which resides in C:. My classpath has the entry ".;C:\sqljdbc4.jar". To accomplish the connection, i'm using the following lines of code:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://ServerIP:1433;databaseName=dbName";
String user = "dbUserID";
String pass = "dbUserPassword";
Connection connection = DriverManager.getConnection(url, user, pass);
However, i get an exception on the line "Connection connection =DriverManager.getConnection(url, user, pass);" : "The TCP/IP connection to the host "ServerIP", 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."
I've checked that the windows firewall is off (And it also has the exception added for MSSQLSERVER port 1433 tcp on both home and public networks). From sql server management studio, i've enabled TCP/IP for both sql server and sql server express.
Can anyone point me what might be wrong with the connection string or sql server connection settings?