Home ProgrammingJava Solution of com.microsoft.sqlserver.jdbc.SQLServerException

Solution of com.microsoft.sqlserver.jdbc.SQLServerException

by Log Raj Bhatt
0 comment 1724 views

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.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDB {

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		// TODO Auto-generated method stub
		String dburl="jdbc:sqlserver://localhost\\SQLEXPRESS;user=sa;password=prithvi";
		Connection con=DriverManager.getConnection(dburl);
		String sql="Select * from DevelopmentDB.dbo.UserInfo";
		Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
		ResultSet rs=st.executeQuery(sql);

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.
    select @@SERVERName

    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;
    select @@SERVICENAME

    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.

0 comment

Leave a Reply

Do NOT follow this link or you will be banned from the site!