Getting an error with token type == 0 #37

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@pdodde
pdodde commented Jun 7, 2012

On a failed login I get an error token followed by a token with a type value of zero which throws:

Error: Unrecognised token 0 at offset 76
at Parser.nextToken (./node_modules/tedious/lib/token/token-stream-parser.js:97:15)
at Parser.addBuffer (./node_modules/tedious/lib/token/token-stream-parser.js:65:17)
at Connection.sendPacketToTokenStreamParser (./node_modules/tedious/lib/connection.js:439:35)
at Connection. (./node_modules/tedious/lib/connection.js:103:23)
at Connection.dispatchEvent (./node_modules/tedious/lib/connection.js:375:59)
at MessageIO. (./node_modules/tedious/lib/connection.js:329:20)
at MessageIO.emit (events.js:67:17)
at MessageIO. (./node_modules/tedious/lib/message-io.js:47:12)
at Socket. (./node_modules/tedious/lib/message-io.js:3:59)
at Socket.emit (events.js:67:17)

Should that be discarded?

@pekim
Collaborator
pekim commented Jun 7, 2012

I'm not sure what's going on. I'd like to see the data returned before we decide how to fix it.
Can you enable some debugging logging please?

In your connection config object can you enable all debug logging options please?

var config = {...}
config.options = {}
config.options.debug = {
    packet: true,
    data: true,
    payload: true,
    token: true,
    log: true
}

Then on the Connection object, log debug events.

connection.on('debug', function(text) }
    console.log(text)
});

This should produce a whole bunch of debug data. If you can add it to this issue (or as a gist), then I'll take a look at it.

@pdodde
pdodde commented Jun 7, 2012

I'm not sure what's going on either. I had run it with debugging on but that output made less sense to me and gave me an error in a different spot. Here it is:

Sent
type:0x12(PRELOGIN), status:0x01(EOM), length:0x002F, spid:0x0000, packetId:0x01, window:0x00
0000 00001A00 06010020 00010200 21000103 00220004 04002600 01FF0000 00010001 ....... ....!... ."....&. ........
0020 02000000 000000 .......
PreLogin - version:0.0.0.1 1, encryption:0x02(NOT_SUP), instopt:0x00, threadId:0x00000000, mars:0x00(OFF)
State change: Connecting -> SentPrelogin

Received
type:0x04(TABULAR_RESULT), status:0x01(EOM), length:0x0025, spid:0x0000, packetId:0x01, window:0x00
0000 00001500 0601001B 00010200 1C000103 001D0000 FF080007 F7000002 00 ........ ........ ........ .....

./node_modules/tedious/node_modules/sprintf/lib/sprintf.js:106
throw(sprintf('[sprintf] expecting number but found %s', get_type(arg)));
^
[sprintf] expecting number but found undefined

@pekim
Collaborator
pekim commented Jun 7, 2012

The failure to decode the prelogin response is because of some assumptions made about the presence of some prelogin option tokens that are absent from this response. If you turned off the payload debugging option, it would probably get past this error, and we might be able to figure out what the later problem is all about.

    payload: false,

Decoding the prelogin response by hand, it looks like the server is reporting its version as 8.00.2039, which is SQL Server 2000 SP4.
Tedious only supports TDS version 7.2, which was introduced with SQL Server 2005 (http://pekim.github.com/tedious/). SQL Server 2000 only supports TDS 7.1.

I might add support for 7.1 at some point in the future, but it's not a high priority for me at the moment. Sorry.

@pdodde pdodde closed this Jun 7, 2012
@pdodde
pdodde commented Jun 7, 2012

Well that makes sense. Do you have any tips/suggestions for me if I try to
add 7.1 support to your driver? Any thoughts on how hard it would be? I'm
not even sure where to find the documentation.

I closed the pull request.

Thanks,
Phil

On Thu, Jun 7, 2012 at 3:03 PM, Mike D Pilsbury <
reply@reply.github.com

wrote:

The failure to decode the prelogin response is because of some assumptions
made about the presence of some prelogin option tokens that are absent from
this response. If you turned off the payload debugging option, it would
probably get past this error, and we might be able to figure out what the
later problem is all about.

   payload: false,

Decoding the prelogin response by hand, it looks like the server is
reporting its version as 8.00.2039, which is SQL Server 2000 SP4.
Tedious only supports TDS version 7.2, which was introduced with SQL
Server 2005 (http://pekim.github.com/tedious/). SQL Server 2000 only
supports TDS 7.1.

I might add support for 7.1 at some point in the future, but it's not a
high priority for me at the moment. Sorry.


Reply to this email directly or view it on GitHub:
#37 (comment)

@pekim
Collaborator
pekim commented Jun 8, 2012

There is documentation for TDS in HTML http://msdn.microsoft.com/en-us/library/dd304523(v=PROT.13).aspx, and PDF http://download.microsoft.com/download/a/e/6/ae6e4142-aa58-45c6-8dcf-a657e5900cd3/[MS-TDS].pdf formats. Unfortunately the protocol version specific details (for 7.1, 7.2, 7.3 etc) are dotted around the documentation, and not in one place. Search for "7.1", "7.2" and so on to find them.

A good place to start would be to allow the protocol version used to be supplied in the Connection constructor's config.options object (defaulting to 7.2 for compatibility with the current support in tedious). This value should then be passed (in place of the currently hardcoded 7.2) in the LOGIN7 packet (http://msdn.microsoft.com/en-us/library/dd304019(v=prot.13) ) that is sent to the server. The LOGINACK (http://msdn.microsoft.com/en-us/library/dd340651(v=prot.13) ) token in the login response contains the TDS version that the server will use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment