请求错误:{message:'请求只能在LoggedIn状态,而不是SentLogin7WithStandardLogin状态',代码:' EINVALIDSTATE' }

时间:2015-12-02 00:21:45

标签: sql-server node.js npm tedious

在使用包tedious连接到MSSQL时,我的请求测试出现以下错误:

  

'请求只能在LoggedIn状态下进行,而不是SentLogin7WithStandardLogin状态',代码:' EINVALIDSTATE'

我的代码(摘自示例: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 提前谢谢。

1 个答案:

答案 0 :(得分:3)

我的问题是超时连接。

err事件上的

connect参数正在返回以下消息:

  

{message:'无法连接到ip_my_server:1433 in 15000ms',代码:'ETIMEOUT'}

在项目的github中查看我对@arthurschreiber的评论: https://github.com/pekim/tedious/issues/344#issuecomment-161320176

谢谢@arthurschreiber