node-mssql icon indicating copy to clipboard operation
node-mssql copied to clipboard

Cannot connect no matter what. No error message either

Open Zhoros opened this issue 2 months ago • 3 comments

const sql = require('mssql/msnodesqlv8');

(async () => {
  try {
    await sql.connect("Driver={SQL Server Native Client 11.0};Server=localhost\\SQLEXPRESS;Database=MyDB");
    const result = await sql.query`select TOP 10 * from MyTable`;
    console.dir(result);
  } catch (err) {
    console.error(err);
  }
})();

Error:

D:\testt>node main.js
ConnectionError: [object Object]
    at PrivateConnection.callback2 (D:\testt\node_modules\mssql\lib\msnodesqlv8\connection-pool.js:46:17)
    at Immediate.<anonymous> (D:\testt\node_modules\msnodesqlv8\lib\connection.js:47:14)
    at process.processImmediate (node:internal/timers:485:21) {
  code: undefined
}

The worst part is the code: undefined. There is nothing I can do to debug this. Using the alternative library: https://www.npmjs.com/package/msnodesqlv8 I can connect using ODBC driver and it connects just fine. But for this library it will not connect no matter what I do. There is no error message either

Zhoros avatar Nov 05 '25 06:11 Zhoros

Please provide the versions of the packages you are using.

You should be able to attach a debugger and debug this, just because the underlying error doesn't expose a code doesn't prevent this from being debugged.

dhensby avatar Nov 05 '25 08:11 dhensby

~~Fixed in https://github.com/tediousjs/node-mssql/commit/a82be0ca33d1715d61e0250d0958b4da138c253a~~ Update to v12.1.1 to get more information

alexsch01 avatar Nov 25 '25 16:11 alexsch01

thanks @alexsch01 but I'm not sure that presenting the error actually fixes the issue of "cannot connect...", it simply surfaces and error that could be collected by attaching a debugger.

dhensby avatar Nov 25 '25 22:11 dhensby