MS SQL Query taking 3 to 4 sec to return result

Aswathy K J 96 Reputation points
2021-02-23T05:50:23.46+00:00

In our application the query execution taking 3565ms of avg. time, when same query is executed directly in DB it is taking only 205ms of avg. From the thread dump it is noticed that socketRead is taking 80% time of execution.

com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:401)

com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:204)

com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:224)

com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2713)

com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7344)

com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:479)

com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:546)

com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:7738)

com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:6494)

com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1983)

java.net.SocketInputStream.read(SocketInputStream.java:141)

java.net.SocketInputStream.read(SocketInputStream.java:170)

java.net.SocketInputStream.socketRead(SocketInputStream.java:116)

java.net.SocketInputStream.socketRead0(Native Method)

Is there any way to reduce this time?

SQL Server Other
{count} votes

Accepted answer
  1. Aswathy K J 96 Reputation points
    2021-02-24T06:25:44.937+00:00

    Problem got resolved after setting following property in the jdbc url : sendStringParametersAsUnicode=false

    for example : jdbc:sqlserver://server;instanceName=yourInstance;databaseName=yourDBName;sendStringParametersAsUnicode=false;

    Thank you.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.