tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 465 forks source link

Host\instance connection timeout #1501

Closed fh-sauleau closed 1 year ago

fh-sauleau commented 1 year ago

Hello Problem on connection, i have two different hard system, with the first one the code work on the second no. I get an error timeout.

i need to connect to a mssql server with instance, on my first system, no problem, but on the second i get a timeout

ConnectionError: Failed to connect to host\instance in 15000ms
    at Connection.<anonymous> (~/test/node_modules/mssql/lib/tedious/connection-pool.js:68:17)
    at Object.onceWrapper (node:events:628:26)
    at Connection.emit (node:events:513:28)
    at Connection.connectTimeout (~/test/node_modules/tedious/lib/connection.js:1195:10)
    at Timeout._onTimeout (~/test/node_modules/tedious/lib/connection.js:1157:12)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7) {
  code: 'ETIMEOUT',
  originalError: ConnectionError: Failed to connect to host\instance in 15000ms
      at ConnectionError (~/test/node_modules/tedious/lib/errors.js:13:12)
      at Connection.connectTimeout (~/test/node_modules/tedious/lib/connection.js:1195:54)
      at Timeout._onTimeout (~/test/node_modules/tedious/lib/connection.js:1157:12)
      at listOnTimeout (node:internal/timers:564:17)
      at process.processTimers (node:internal/timers:507:7) {
    code: 'ETIMEOUT'
  }
}

for testing purpose i've created a tmp mssql server without instance and connection work fine, so i guess the problem is on the instance param, but can't determine where.

Test Code:

const sql = require('mssql');

let config = {
    server: "host",
    database: "database",
    user: "user",
    password: "pass",
    options: {
        instanceName: "instance",
    }
}

(async () => {
    try {
            sql.connect(config)
    } catch (err) {
        console.error ( err );
    }
})();

setTimeout ( ()=>{process.exit ( );}, 20000 );

tested with no instanceName but server: "host\\instance", nothing change.

Software versions:

work with:

nodejs : v18.16.1 npm : 9.5.1 mssql : 6.2.0 tedious : 6.7.1

don't work with:

nodejs : v18.13.0 npm : 9.2.0 mssql : 6.4.1 tedious : 6.7.1

dhensby commented 1 year ago

v6.4.1 is no longer supported. Please upgrade to v9.

fh-sauleau commented 1 year ago

thank you for your help but don't close before the problem was solved

still don't work: nodejs : v18.13.0 npm : 9.2.0 mssql : 9.1.1 mssql/tedious : 15.1.3 tedious : 6.7.1

dhensby commented 1 year ago

These errors are almost always firewall related. Have you done any debugging? For instance, can you connect via sqlcmd?

Have you run with debugging output on to see what tedious is up to when trying to authenticate?

fh-sauleau commented 1 year ago

of course that was the first thing i try, work perfectly with dbeaver, and check with the admin sys, no firewall, no proxy, ping pass without problem.

how to run with debug on tedious ?

dhensby commented 1 year ago

You can get debug output by setting the DEBUG=* environment variable

fh-sauleau commented 1 year ago

only setting DEBUG var does nothing, i've tried

DEBUG=*
DEBUG=1
DEBUG=true
DEBUG=TRUE
DEBUG=debug

same result, i'm not sure to well understand what you mean

dhensby commented 1 year ago

It needs to be set for the process running your application code. Then debug output will be shown in the console


eg: $ DEBUG=* node app.js (on a *nix shell)

fh-sauleau commented 1 year ago

ok, thank you, i just did it result:

  mssql:base pool(1): created +0ms
  mssql:base pool(1): connecting +4ms
  mssql:tedi pool(1): connection #1 created +0ms
  mssql:tedi connection(1): establishing +0ms
13~/test/node_modules/mssql/lib/tedious/connection-pool.js:70
          err = new ConnectionError(err)
                ^

ConnectionError: Failed to connect to host\instance in 15000ms
    at ~/test/node_modules/mssql/lib/tedious/connection-pool.js:70:17
    at Connection.onConnect (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1012:9)
    at Object.onceWrapper (node:events:628:26)
    at Connection.emit (node:events:513:28)
    at Connection.emit (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1040:18)
    at Connection.connectTimeout (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1254:10)
    at Timeout._onTimeout (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1199:12)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7) {
  code: 'ETIMEOUT',
  originalError: ConnectionError: Failed to connect to host\instance in 15000ms
      at Connection.connectTimeout (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1254:26)
      at Timeout._onTimeout (~/test/node_modules/mssql/node_modules/tedious/lib/connection.js:1199:12)
      at listOnTimeout (node:internal/timers:564:17)
      at process.processTimers (node:internal/timers:507:7) {
    code: 'ETIMEOUT',
    isTransient: undefined
  }
}
dhensby commented 1 year ago

Hm, ok - I'm a bit confused as I expected there to be output for tedious there too, but it's only mssql. I thought that tedious uses the debug library, but I can see that they don't. You'll need to attach some listeners to tedious' debug event if you want to see what is going on.

The issues in this repository are for bugs, not debugging support. I'd recommend you go through some debugging steps to see what the root cause of the problem is and, if that is a bug with the library, we can look into it. At the moment, it just seems tedious can't connect to the instance and there's no information on why that is or what part of the library may be at fault for that.

Another route to rule out an issue with this library is to write a test script that connects to the database using tedious directly, if that works then it indicates a problem with this library, if it doesn't it indicates something with tedious (or possibly something external).

fh-sauleau commented 1 year ago

ok, thank you, i'll try to do it

fh-sauleau commented 1 year ago

ok i tried to connect with only tedious and same problem, same messages. I catch tedious events : debug / error / errorMessage / infoMessge, nothing more

dhensby commented 1 year ago

Thanks for trying that. That means the problem is outside the scope of this library as it's either a driver issue (you can raise it there) or it's some other infrastructure issue.