2

Trying to connect o MS SQL server that runs on the same Win 10 machine with my project in Eclipse:

 String url = "jdbc:sqlserver://GOLD\\SQLEXPRESS;databaseName=PrintLog;";
 Connection conn = DriverManager.getConnection(url ,"user","passwd");

But got exception:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host GOLD, named instance sqlexpress failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.  For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.

Computer name is GOLD. I can connect to DB from C# without problem. Authentication is enabled both windows and SQL server. I'm expecting to get Windows authentication while connect

SQL server properties: enter image description here

How to find the problem?

UPD

I got better result by adding port number to connect string:

String url = "jdbc:sqlserver://GOLD\\SQLEXPRESS:1433;databaseName=PrintLog;";

Does it means that default port number is different?

vico
  • 17,051
  • 45
  • 159
  • 315
  • Possible duplicate of [JDBC connection to MSSQL server in windows authentication mode](https://stackoverflow.com/questions/16497998/jdbc-connection-to-mssql-server-in-windows-authentication-mode) – Ori Marko Jun 24 '18 at 14:52
  • Here's [a similar question](https://stackoverflow.com/questions/51008747/sqlexception-error-when-connecting-with-java) with named instance considerations. – Dan Guzman Jun 24 '18 at 15:19
  • Have you followed the instructions from the error message? _"Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host."_ – Mark Rotteveel Jun 24 '18 at 15:22
  • I placed rule on port 1433 and tried to telnet to it, but connection is refused – vico Jun 24 '18 at 15:46
  • I got better result by adding port number to connect string. Does it means that default port number is different? – vico Jun 25 '18 at 11:02
  • @vico It worked the same way to me too. Used 1433 port and it worked. Earlier I didn't specify the port number and it thrown error. Now after adding port number it's all fine. – Suresh Feb 10 '20 at 16:17

0 Answers0