tediousjs / tedious

Node TDS module for connecting to SQL Server databases.
http://tediousjs.github.io/tedious/
MIT License
1.57k stars 436 forks source link

DLL error on connecting to Latin1_General_BIN collation server #1195

Open MasterOdin opened 3 years ago

MasterOdin commented 3 years ago

When using tedious, I cannot connect to SQL Server using the Latin1_General_BIN collation created using the docker image that MS puts out. The server is created using the following command:

docker run --rm -d --name sqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password(12)" -e "MSSQL_COLLATION=Latin1_General_BIN" mcr.microsoft.com/mssql/server:2017-latest

When attempting to connect, I get the following error:

RequestError: Could not load the DLL (server internal), or one of the DLLs it references. Reason: 126(The specified module could not be found.).
    at Parser.<anonymous> (/tmp/test/node_modules/tedious/lib/connection.js:1153:27)
    at Parser.emit (events.js:314:20)
    at Parser.<anonymous> (/tmp/test/node_modules/tedious/lib/token/token-stream-parser.js:35:14)
    at Parser.emit (events.js:314:20)
    at addChunk (/tmp/test/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:298:12)
    at readableAddChunk (/tmp/test/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:280:11)
    at Parser.Readable.push (/tmp/test/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:241:10)
    at Parser.Transform.push (/tmp/test/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:139:32)
    at doneParsing (/tmp/test/node_modules/tedious/lib/token/stream-parser.js:122:14)
    at /tmp/test/node_modules/tedious/lib/token/infoerror-token-parser.js:48:5 {
  code: 'EREQUEST',
  number: 17750,
  state: 0,
  class: 16,
  serverName: '04ed0a6c188f',
  procName: 'sp_executesql',
  lineNumber: 1
}

with the following lines being emitted by sqlserver in its error log:

2020-12-24 01:36:03.31 spid51      Error: 17750, Severity: 16, State: 0.
2020-12-24 01:36:03.31 spid51      Could not load the DLL (server internal), or one of the DLLs it references. Reason: 126(The specified module could not be found.)

I used the example connection code from the Getting Started section with the following configuration object:

var config = {
  server: "localhost",
  options: {
    database: 'master',
    encrypt: false
  },
  authentication: {
    type: "default",
    options: {  
      userName: "sa",
      password: "Password(12)",
    }
  }
};

I can connect to and query the server just fine using the following clients:

arthurschreiber commented 3 years ago

I can reproduce this, even with the mcr.microsoft.com/mssql/server:2019-latest container. I'll try and see what those other libraries do differently.

@IanChokS can you reach out to the SQLServer on Linux folks and see if they have an idea what's going on here? 🙇‍♂️

IanChokS commented 3 years ago

@MasterOdin I was able to get a successful connection and query using: docker version: 20.10.0, build 7287ab3 mssql verision: mcr.microsoft.com/mssql/server:2017-latest node version: v12.16.1 tedious version: 9.2.1 docker run command:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password(12)" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest

sql column collation: Latin1_General_BIN.

I'm not sure what's causing your issue, but you can try removing that docker image and re-downloading it. I'm guessing a few files were corrupted when pulling the images from docker.

MasterOdin commented 3 years ago

@IanChokS, I'm confused to what you're getting at there. Your docker run command removes the MSSQL_COLLATION environment variable and so the server is set-up to use the default of SQL_Latin1_General_CP1_CI_AS. Sure, I can individually cast individual databases, tables, or columns to Latin1_General_BIN and tedious will then work fine, but as soon as I want the server itself in Latin1_General_BIN, then tedious would break again, putting me back into my original issue.

To your last point on corrupted images, I've replicated this issue across two machines (and @arthurschreiber has replicated it as well on their end) that it would be that MSFT themselves are publishing bugged versions of SQLServer I guess, but then again, 5 other clients seem to have no issues with it, which I would think would be the case of a corrupted image.

IanChokS commented 3 years ago

Oh yes my bad 🤦‍♂️ I missed the -e "MSSQL_COLLATION=Latin1_General_BIN" in the run command, I'm seeing the issue as well

IanChokS commented 3 years ago

OK I've posted help on the Microsoft forum: https://docs.microsoft.com/en-us/answers/questions/221376/dll-error-on-connecting-to-latin1-general-bin-coll.html

I'll keep this discussion updated if I hear anything back from their side!