I am currently using the following connection string to connect to the database (the database is on the same server as ServerIP):
String constr = "Data Source=ServerIP,1433;Network Library=DBMSSOCN;Initial Catalog=dbName;User ID=dbUserID;Password=dbUserPassword";
This connection works great when used with asp.net. (I manually created dbUserId and assigned it dbUserPassword from sql server management studio. DbUserId is the owner of the dbName database)
I have a java swing application on another PC where I need to connect to one database. I am using sqljdbc4.jar, which is located in C :. My class has an entry ".; C: \ sqljdbc4.jar". To make the connection, I use 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 in the line "Connection connection = DriverManager.getConnection (url, user, pass);": "TCP / IP connection to host" ServerIP ", port 1433 failed. Error:" Connection timed out. Check connection properties. Verify that the instance of SQL Server is running on the host and accepts TCP / IP connections on the port. Ensure that TCP connections to the port are not blocked by the firewall. "
I checked that the Windows Firewall is turned off (And he also added an exception for the MSSQLSERVER 1433 tcp port on both home and public networks). From sql server management studios, I have enabled TCP / IP for SQL Server and SQL Server Express.
Can someone tell me what might be wrong in the connection settings or connection settings to sql server?
source share