Skip to content

Error connecting to MSSQL database with clustering enabled #1669

@nick-w-nick

Description

@nick-w-nick

Software versions

  • Tedious: 18.6.1
  • SQL Server: 2019
  • Node.js: 18

Additional Libraries Used and Versions
kysely v0.27.4 (query builder)
tarn v3.0.2 (connection pooling)

Table schema
N/A

Connection configuration
Standard config using default authentication method via username and password.

Problem description
I am trying to connect to a MSSQL database that has clustering enabled, but am getting the following error:

/Users/user/Documents/service-name/node_modules/tedious/src/token/handler.ts:140
    throw new UnexpectedTokenError(this, token);
          ^
UnexpectedTokenError: Unexpected token `ENVCHANGE` in `RequestTokenHandler`
    at RequestTokenHandler.onDatabaseMirroringPartner (/Users/user/Documents/service-name/node_modules/tedious/src/token/handler.ts:140:11)

This error is not present when connecting to our other identical MSSQL databases where clustering/hadr is disabled.

The weirdest thing about this is we have other services that connect to the exact same database, but use Sequelize instead of Kysely, and they work just fine. They both use Tedious as the driver, so you would assume that they would also connect identically as well, but for some reason they do not.

We have also verified that we don't seem to have database mirroring enabled, but are somehow still getting sent a DatabaseMirroringPartner event, which is causing the unhandled exception to be thrown.

Something of note may be that it seems like it connects to the database and runs the first query, but directly after returning the result of the query it throws the unexpected token error.

Expected behavior
Query runs and returns values

Actual behavior
Query runs, returns the result then immediately crashes the process

Error message/stack trace

/Users/user/Documents/service-name/node_modules/tedious/src/token/handler.ts:140
    throw new UnexpectedTokenError(this, token);
          ^
UnexpectedTokenError: Unexpected token `ENVCHANGE` in `RequestTokenHandler`
    at RequestTokenHandler.onDatabaseMirroringPartner (/Users/user/Documents/service-name/node_modules/tedious/src/token/handler.ts:140:11)

Any other details that can be helpful
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions