我正在尝试从数据库中获取数据,但收到以下错误{消息:'请求只能在 LoggedIn 状态下进行,而不是 SentClientRequest 状态',代码:'EINVALIDSTATE'}。如果我只调用一个查询函数,那么它可以工作,但不能用于多个
下面是我的代码
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
if(!err)
{
console.log("Connected");
executeStatement();
executeStatement2();
}
else
{
console.log(err);
}
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
function executeStatement() {
request = new Request("Select p.product_name, s.product_id, s.price, s.create_date, s.update_date from products p left join sale s on (p.id = s.product_id) order by CONVERT(datetime, s.update_date ) desc ;", function(err) {
if (err) {
console.log(err);}
});
request.on('row', function(columns) {
var rowObject ={};
columns.forEach(function(column) {
rowObject[column.metadata.colName] = column.value;
});
var jsonArray = [];
jsonArray.push(rowObject);
});
connection.execSql(request);
}
function executeStatement2() {
request = new Request("Select * from products ;", function(err) {
if (err) {
console.log(err);
}
});
request.on('row', function(columns) {
var rowObject ={};
columns.forEach(function(column) {
rowObject[column.metadata.colName] = column.value;
});
var jsonArray2 = [];
jsonArray2.push(rowObject);
});
connection.execSql(request);
}