在使用包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);
});
答案 0 :(得分:3)
我的问题是超时连接。
err
事件上的 connect
参数正在返回以下消息:
{message:'无法连接到ip_my_server:1433 in 15000ms',代码:'ETIMEOUT'}
在项目的github中查看我对@arthurschreiber的评论: https://github.com/pekim/tedious/issues/344#issuecomment-161320176