sql-servernode.jsnpmtedious

Request error: { message: 'Requests can only be made in the LoggedIn state, not the SentLogin7WithStandardLogin state', code: 'EINVALIDSTATE' }


I get following error on my test of request, when using package tedious for connecting to MSSQL:

'Requests can only be made in the LoggedIn state, not the SentLogin7WithStandardLogin state', code: 'EINVALIDSTATE'

My code (extract from example: http://pekim.github.io/tedious/getting-started.html):

<!-- testDb.js -->

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

var config = {
    userName: 'xpto',
    password: 'pass',
    server: 'myserver',
    options: { encrypt: true, database: 'dbname' }
};

var connection = new Connection(config);

connection.on('connect', function (err) {
    var Request = require('tedious').Request;
    request = new Request("select 42, 'hello world'", function (err, rowCount) {
        if (err) {
            console.log('ERROR');
            console.log(err);
        } else {
            console.log(rowCount + ' rows');
        }
    });

    request.on('row', function (columns) {
        columns.forEach(function (column) {
            console.log(column.value);
        });
    });

    connection.execSql(request);
});

enter image description here Thanks in advance.


Solution

  • My problem is with timeout connection.

    err parameter on the connect event is returning following message:

    { message: 'Failed to connect to ip_my_server:1433 in 15000ms', code: 'ETIMEOUT' }

    See the comment, of @arthurschreiber, to my question in github of project: https://github.com/pekim/tedious/issues/344#issuecomment-161320176

    Thanks @arthurschreiber!