Node-mssql: "connection.on not a function" when using msnodesqlv8?

Created on 15 Feb 2018  Â·  2Comments  Â·  Source: tediousjs/node-mssql

Here's my working config using default driver (tedious)

const sql   = require('mssql');
const pool  = new sql.ConnectionPool({
    user        : 'USER',
    password    : 'PASSWORD',
    server      : 'HOST\\INSTANCE',
    database    : 'DATABASE',
    options     : {
        useUTC: false
    }
});
pool.on('error', err => {
    if (err)  console.log('sql errors', err);
    if (!err) pool.connect();
});
pool.connect();

But when I change to const sql = require('mssql/msnodesqlv8'), I get the error message

TypeError: connection.on is not a function at parent.acquire (app\node_modules\mssql\lib\tedius.js:868:20)

Why is it still using tedious? I'm telling it to use msnodesqlv8.

Also on a related note: msnodesqlv8 DOES support TVP according to commits in December, and I'll test it just as soon as I can get this library to actually use msnodesqlv8 instead of Tedious.

Most helpful comment

I was having this exact error minutes ago. There’s at least one thing I see immediately that I’ll mention, as well as telling you how I solved the error on my end.

First, your config for your connection pool is missing an item I have. I have a driver: "msnodesqlv8" config, and I wonder if adding that would solve your problem. E.G
const pool = new sql.ConnectionPool({ user : 'USER', password : 'PASSWORD', server : 'HOST\\INSTANCE', driver : ‘msnodesqlv8’, database : 'DATABASE', options : { useUTC: false }

Now, as far as what happened on my end is, I was importing ‘mssql/msnodesqlv8’ in one module, but in a different module I was importing a specific function straight from ‘mssql’. Once I changed that other import to ‘mssql/msnodesqlv8’ my project ran successfully, so I can suggest searching your code for any imports of ‘mssql’ to see if that helps.

All 2 comments

I was having this exact error minutes ago. There’s at least one thing I see immediately that I’ll mention, as well as telling you how I solved the error on my end.

First, your config for your connection pool is missing an item I have. I have a driver: "msnodesqlv8" config, and I wonder if adding that would solve your problem. E.G
const pool = new sql.ConnectionPool({ user : 'USER', password : 'PASSWORD', server : 'HOST\\INSTANCE', driver : ‘msnodesqlv8’, database : 'DATABASE', options : { useUTC: false }

Now, as far as what happened on my end is, I was importing ‘mssql/msnodesqlv8’ in one module, but in a different module I was importing a specific function straight from ‘mssql’. Once I changed that other import to ‘mssql/msnodesqlv8’ my project ran successfully, so I can suggest searching your code for any imports of ‘mssql’ to see if that helps.

closing as outdated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brilvio picture brilvio  Â·  3Comments

cdeutsch picture cdeutsch  Â·  6Comments

jeetendra-choudhary picture jeetendra-choudhary  Â·  3Comments

srglovin picture srglovin  Â·  4Comments

andrewmcgivery picture andrewmcgivery  Â·  5Comments