Solution of com.microsoft.sqlserver.jdbc.SQLServerException

While I returned to eclipse to test a simple jdbc related program after couple of months, I encountered some kind of error.

Let’s have look at my code.

Now While running this program I got following exception in console.

Exception in thread “main” com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host localhost, 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.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:5247)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1871)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1608)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at TestDB.main(TestDB.java:14)

Solving com.microsoft.sqlserver.jdbc.SQLServerException

Error

Now I do as per the instruction in the error.

  1. Server name is fine. localhost or Name of pc is fine for server name. or run this code in Sqlserver.

    This code will display name of server
  2. Instance name: It is very difficult to  find instance name for me. After checking a manual i find a code to find instance name;

    This code will print name of instance.

    After executing these code I got – MSSQLSERVER as instance name.

I replaced SQLEXPRESS by MSSQLSERVER and my code run fine.

Do not forget to revert with your feedback and suggestions.

Log Raj Bhatt

A Computer Science Student and Java Developer.

Leave a Reply

Your email address will not be published. Required fields are marked *