none
TDS Protocol error: Invalid packet type 0x11

    Question

  • Hi,

               We are using SQL Server 2005 SP2 with Hibernate, JTDS 1.2.2 JDBC Driver and Sun Application Server. We have a clustered environment in the application server. One of the servers in the cluster is working fine, but the other server is not able to connect to the database and is throwing the following exception. Please let me know if any of you have seen the error before or any solution to fix it. Your help is greatly appreciated.

        05 Sep 2009 16:47:25,250  WARN httpSSLWorkerThread-80-0 AbstractBatcher:318 - Could not close a JDBC result set
      java.sql.SQLException: TDS Protocol error: Invalid packet type 0x11
                    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2314)
                    at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:764)
                    at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:593)
                    at net.sourceforge.jtds.jdbc.JtdsResultSet.close(JtdsResultSet.java:486)
                    at org.hibernate.jdbc.AbstractBatcher.closeStatements(AbstractBatcher.java:314)
                    at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:382)
                    at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:324)
                    at org.hibernate.impl.SessionImpl.close(SessionImpl.java:298)
                    at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession(SessionFactoryUtils.java:774)
                    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.closeSession(OpenSessionInViewFilter.java:280)

     Caused by: net.sourceforge.jtds.jdbc.ProtocolException: Invalid packet type 0x11
                    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2301)
                    ... 43 more

     05 Sep 2009 16:47:25,250  WARN httpSSLWorkerThread-80-0 AbstractBatcher:280 - exception clearing maxRows/queryTimeout
     java.sql.SQLException: "Connection has been returned to pool and this reference is no longer valid.
                    at net.sourceforge.jtds.jdbcx.proxy.StatementProxy.validateConnection(StatementProxy.java:688)
                    at net.sourceforge.jtds.jdbcx.proxy.StatementProxy.getMaxRows(StatementProxy.java:134)
                    at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:276)
                    at org.hibernate.jdbc.AbstractBatcher.closeStatements(AbstractBatcher.java:330)
                    at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:382)
                    at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:324)
                    at org.hibernate.impl.SessionImpl.close(SessionImpl.java:298)
                    at org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession(SessionFactoryUtils.java:774)


    Thanks,
    Sampath

    Friday, September 11, 2009 1:57 PM

Answers

  • Sampath,
      JTDS is not a Microsoft-supported driver, and this error indicates that the JTDS driver is not properly understanding the messages the server is sending. I'd recommend you try the following (in order from easiest fix to hardest fix, for you):

    1) Check if there is a newer version of the JTDS driver available, and see if upgrading it fixes the problem
    2) Look for a JTDS forum or JTDS customer support to see if they can resolve your problem.
    3) Switch from the JTDS driver to the Microsoft-supported JDBC driver for SQL Server: http://msdn.microsoft.com/en-us/data/aa937724.aspx
    This post is provided 'as is' and confers no express or implied warranties or rights.
    Friday, September 11, 2009 4:46 PM
    Moderator

All replies

  • Sampath,
      JTDS is not a Microsoft-supported driver, and this error indicates that the JTDS driver is not properly understanding the messages the server is sending. I'd recommend you try the following (in order from easiest fix to hardest fix, for you):

    1) Check if there is a newer version of the JTDS driver available, and see if upgrading it fixes the problem
    2) Look for a JTDS forum or JTDS customer support to see if they can resolve your problem.
    3) Switch from the JTDS driver to the Microsoft-supported JDBC driver for SQL Server: http://msdn.microsoft.com/en-us/data/aa937724.aspx
    This post is provided 'as is' and confers no express or implied warranties or rights.
    Friday, September 11, 2009 4:46 PM
    Moderator
  • Hi Dan,

                       Thanks for your reply.

                       We have the latest version of JTDS installed. We have been using JTDS driver for more than a year and this is the first time we are facing this issue. Moreover, the issue happens randomly. So we are not sure if it is a JTDS related issue or something else.

                       I contacted the JTDS tech support and they said "The first guess would be that something (another thread) is kicking in while data is read from the server, e.g. a timeout or such. " Do you think that could be an issue?

    Thanks,
    Sampath
    Tuesday, September 15, 2009 1:56 PM
  • I also believe this is JTDS issue. Type 0x11 looks like an SSL packet which has the first byte between 0x11-0x13(or some value around this).  Most likely the driver consider the SSL packet as a pure TDS packet and failed.
    Thanks.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, September 15, 2009 6:30 PM
    Moderator
  • I was looking into the source code for JTDS driver and if you look at line 2241 in the below code, the invalid packet type error is thrown if JTDS couldn't recognize the token type. Also the the characters after "0x" in the error message is the result of "bitwise &" between the token value and 0xFF as mentioned in line 2244. We got the same error couple of days ago with the message " java.sql.SQLException: TDS Protocol error: Invalid packet type 0x5"

     

    Thanks,

    Sampath

     

    try {

    2143             currentToken.token = (byte)in.read();

    2144             switch (currentToken.token) {

    2145                 case TDS5_PARAMFMT2_TOKEN:

    2146                     tds5ParamFmt2Token();

    2147                     break;

    2148                 case TDS_LANG_TOKEN:

    2149                     tdsInvalidToken();

    2150                     break;

    2151                 case TDS5_WIDE_RESULT:

    2152                     tds5WideResultToken();

    2153                     break;

    2154                 case TDS_CLOSE_TOKEN:

    2155                     tdsInvalidToken();

    2156                     break;

    2157                 case TDS_RETURNSTATUS_TOKEN:

    2158                     tdsReturnStatusToken();

    2159                     break;

    2160                 case TDS_PROCID:

    2161                     tdsProcIdToken();

    2162                     break;

    2163                 case TDS_OFFSETS_TOKEN:

    2164                     tdsOffsetsToken();

    2165                     break;

    2166                 case TDS7_RESULT_TOKEN:

    2167                     tds7ResultToken();

    2168                     break;

    2169                 case TDS7_COMP_RESULT_TOKEN:

    2170                     tdsInvalidToken();

    2171                     break;

    2172                 case TDS_COLNAME_TOKEN:

    2173                     tds4ColNamesToken();

    2174                     break;

    2175                 case TDS_COLFMT_TOKEN:

    2176                     tds4ColFormatToken();

    2177                     break;

    2178                 case TDS_TABNAME_TOKEN:

    2179                     tdsTableNameToken();

    2180                     break;

    2181                 case TDS_COLINFO_TOKEN:

    2182                     tdsColumnInfoToken();

    2183                     break;

    2184                 case TDS_COMP_NAMES_TOKEN:

    2185                     tdsInvalidToken();

    2186                     break;

    2187                 case TDS_COMP_RESULT_TOKEN:

    2188                     tdsInvalidToken();

    2189                     break;

    2190                 case TDS_ORDER_TOKEN:

    2191                     tdsOrderByToken();

    2192                     break;

    2193                 case TDS_ERROR_TOKEN:

    2194                 case TDS_INFO_TOKEN:

    2195                     tdsErrorToken();

    2196                     break;

    2197                 case TDS_PARAM_TOKEN:

    2198                     tdsOutputParamToken();

    2199                     break;

    2200                 case TDS_LOGINACK_TOKEN:

    2201                     tdsLoginAckToken();

    2202                     break;

    2203                 case TDS_CONTROL_TOKEN:

    2204                     tdsControlToken();

    2205                     break;

    2206                 case TDS_ROW_TOKEN:

    2207                     tdsRowToken();

    2208                     break;

    2209                 case TDS_ALTROW:

    2210                     tdsInvalidToken();

    2211                     break;

    2212                 case TDS5_PARAMS_TOKEN:

    2213                     tds5ParamsToken();

    2214                     break;

    2215                 case TDS_CAP_TOKEN:

    2216                     tdsCapabilityToken();

    2217                     break;

    2218                 case TDS_ENVCHANGE_TOKEN:

    2219                     tdsEnvChangeToken();

    2220                     break;

    2221                 case TDS_MSG50_TOKEN:

    2222                     tds5ErrorToken();

    2223                     break;

    2224                 case TDS5_DYNAMIC_TOKEN:

    2225                     tds5DynamicToken();

    2226                     break;

    2227                 case TDS5_PARAMFMT_TOKEN:

    2228                     tds5ParamFmtToken();

    2229                     break;

    2230                 case TDS_AUTH_TOKEN:

    2231                     tdsNtlmAuthToken();

    2232                     break;

    2233                 case TDS_RESULT_TOKEN:

    2234                     tds5ResultToken();

    2235                     break;

    2236                 case TDS_DONE_TOKEN:

    2237                 case TDS_DONEPROC_TOKEN:

    2238                 case TDS_DONEINPROC_TOKEN:

    2239                     tdsDoneToken();

    2240                     break;

    2241                 default:

    2242                     throw new ProtocolException(

    2243                             "Invalid packet type 0x" +

    2244                                 Integer.toHexString((int) currentToken.token & 0xFF));

    2245             }

    Tuesday, September 15, 2009 6:46 PM
  • Also this error doesn't happen all the time. It happens randomly and once it happens all the connection objects are closed and we have to restart the application server for the application to work.
    Tuesday, September 15, 2009 7:03 PM
  • Could you solve this issue, i'm having this same problem with one of our applications, it seems to happen randomly too
    ORRM
    Tuesday, August 09, 2011 4:12 PM