Tedious: Connection failed with latest version

Created on 11 Apr 2019  Â·  11Comments  Â·  Source: tediousjs/tedious

Hello guys,

i tried to use sequelize with tedious. I just installed latest version of each package.

An issue occured during a connection to microsoft sql server 2012 thanks to sequelize and [email protected] which return:
SequelizeAccessDeniedError: Login failed for user ''. at Connection.connection.on.err (~/projects/node_modules/sequelize/lib/dialects/mssql/connection-manager.js:107:20) at emitOne (events.js:125:13) at Connection.emit (events.js:221:7) at Connection.message (/node_modules/tedious/lib/connection.js:1972:18) at Connection.dispatchEvent (~/projects/node_modules/tedious/lib/connection.js:1172:36) at MessageIO.messageIo.on (~/projects/node_modules/tedious/lib/connection.js:1045:14) at emitNone (events.js:115:13) at MessageIO.emit (events.js:218:7) at Message.message.on (~/projects/node_modules/tedious/lib/message-io.js:32:14) at emitNone (events.js:120:20) at Message.emit (events.js:218:7) at endReadableNT (~/projects/node_modules/tedious/node_modules/readable-stream/lib/_stream_readable.js:1077:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) name: 'SequelizeAccessDeniedError',.

Here is a sample of code:

const sequelize = new Sequelize(MY_DB,MY_USER,MY_PWD', {
  dialect: 'mssql',
  host: MY_HOST,
  logging: false,
  dialectOptions: {
    encrypt: true,
  },
});

sequelize
  .authenticate()
  .then(() => {
    console.log('Connection has been established successfully to the mssql database.');
  })
  .catch((err) => {
    console.error('Unable to connect to the mssql database:', err);
  });

In this step, i was thinking that is something wrong with sequelize. So i started to use directly tedious but i get same result.
Here the stack trace:

ConnectionError: Login failed for user ''.
    at ConnectionError (~/projects/node_modules/tedious/lib/errors.js:13:12)
    at Parser.tokenStreamParser.on.token (~/projects/node_modules/tedious/lib/connection.js:751:23)

with this connection management:

const Connection = require('tedious').Connection;

const config = {
  server: MY_HOST,
  userName: MY_USER,
  password: MY_PWD,
  database: MY_DB,
};

const connection = new Connection(config);

const Request = require('tedious').Request;

connection.on('connect', (err) => {
  if (err) {
    console.error('Error:', err);
    connection.close();
  }
  console.log('ok');
});

This is why i have created this issue in this project because sequelize depends of tedious.

Anyway, when i rollback to [email protected], below connections work well.

it looks like a tedious issue as this one but it was in 2015.

I'm stay available if some informations are missing


node: v9.0.0
sequelize: 4.43.1

Most helpful comment

Hi @Royalsspirit
I just went through your issue. Looks like you are still trying to use the deprecated way to indicated username and password for connection config. There is a link for a Tedious http://tediousjs.github.io/tedious/api-connection.html. You could check here for details. I will share you an example for how to set the password and username for the current version:
var config = {
server: "localhost",
authentication: {
type: "default",
options: {
userName: "sa",
password: "testPWD123"
}
},
};
I hope this helps.

All 11 comments

Hi @Royalsspirit
I just went through your issue. Looks like you are still trying to use the deprecated way to indicated username and password for connection config. There is a link for a Tedious http://tediousjs.github.io/tedious/api-connection.html. You could check here for details. I will share you an example for how to set the password and username for the current version:
var config = {
server: "localhost",
authentication: {
type: "default",
options: {
userName: "sa",
password: "testPWD123"
}
},
};
I hope this helps.

Hello @MichaelSun90 ,

Indeed, with the object you shared, connection work as expected but it still doesn't work with sequilize.

So, i think it's an issue regarding sequilize.

Thank you for your help.

The npm page and README.md both point to a tutorial on microsoft.com that uses the deprecated config.

Might be good to either update the Microsoft tutorial or point these links to the working Getting Started section in the documentation.

Hi @r-tanner-f
On both pages that you mentioned, there is a Documentation section under it with a link to tediousjs.github.io/tedious/. Under the github.io page, there is a section called API, and a subsection under this section named Connection. You can find the updated details for the configuration there.
Here is a link to that section: http://tediousjs.github.io/tedious/api-connection.html.
Hope this is helpful.

I did find it, thanks, but not before going through a broken tutorial.

On Mon, Apr 15, 2019, 9:54 AM Michael Sun <[email protected] wrote:

Hi @r-tanner-f https://github.com/r-tanner-f
On both pages that you mentioned, there is a Documentation section under
it with a link to tediousjs.github.io/tedious/. Under the github.io page,
there is a section called API, and a subsection under this section named
Connection. You can find the updated details for the configuration there.
Here is a link to that section:
http://tediousjs.github.io/tedious/api-connection.html.
Hope this is helpful.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/tediousjs/tedious/issues/890#issuecomment-483332877,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AD754B_t8P52zVsTCUmKgCoLevBOS0XWks5vhK6_gaJpZM4cpvSG
.

The example under the document has been fixed with the latest config object struct. Hope this helps with the new connection structure.

Indeed @r-tanner-f, npm package was not updated to use last version of tedious that's why i encounter this issue

Any news on this? I still get the login error.

"sequelize": "^4.39.0"
"tedious": "^6.2.0"

@moemar I had to downgrade to tedious 5.0.3 while using sequelize 4.13.8

npm install [email protected]

I was having the same error. I wrote the port in the wrong place:
options: { port: Number(process.env.PORT), },

this solved the problem:
config = { server: 'localhost', port: Number(process.env.PORT), authentication: { type: 'default', }, dialect: 'mssql', };

My credentials are rejected using either config. My current attempt looks like this.

var express = require('express');
var app = express();

app.get('/', function (req, res) {

    var sql = require("mssql");


var config = {
    server: "<server>",
    authentication: {
    type: "default",
    options: {
    userName: "mfad\/afs01",
    password: "<pwd>"
    }
   },
};

    // connect to your database
    sql.connect(config, function (err) {

        if (err) console.log(err);

        // create Request object
        var request = new sql.Request();

        // query to the database and get the records
        request.query('select * from mytest', function (err, recordset) {

            if (err) console.log(err)

            // send records as a response
            res.send(recordset);

        });
    });
});

var server = app.listen(5000, function () {
    console.log('Server is running..');
});
Was this page helpful?
0 / 5 - 0 ratings