我不能使用 tedious on Request 的回调(这是一个 INSERT 请求)在第一个请求之后发出另一个请求。任何想法 ?这是我的代码。
function intermediaryPositionSQL(decodeMessage, connection) {
if (typeof (decodeMessage.latitudeInt) != "undefined" && typeof (decodeMessage.longitudeInt) != "undefined")
{
var request = new Request(requestPosQuery, function (error)
{
if (error) {
winston.error(error);
}
});
request.addParameter('v_pos_latitude', TYPES.Float, decodeMessage.latitudeInt);
request.addParameter('v_pos_longitude', TYPES.Float, decodeMessage.longitudeInt);
request.addParameter('v_pos_altitude', TYPES.Int, (typeof (decodeMessage.altitude) != "undefined") ? decodeMessage.altitude : null);
request.addParameter('v_pos_speed', TYPES.Int, (typeof (decodeMessage.speed) != "undefined") ? decodeMessage.speed : null);
request.addParameter('v_pos_move', TYPES.Int, decodeMessage.move);
request.addParameter('v_pos_type', TYPES.Int, 2);
request.addParameter('v_pos_device', TYPES.VarChar, decodeMessage.device);
request.addParameter('v_pos_timestamp', TYPES.Int, decodeMessage.time);
request.on('doneInProc', function (rowCount, more, rows) {
return;
});
connection.execSql(request);
} else {
return;
}
}
function actualPositionSQL(decodeMessage, connection) {
if (typeof (decodeMessage.latitude) != "undefined" && typeof (decodeMessage.longitude) != "undefined")
{
var request = new Request(requestPosQuery, function (error)
{
if (error) {
winston.error(error);
}
});
request.addParameter('v_pos_latitude', TYPES.Float, decodeMessage.latitude);
request.addParameter('v_pos_longitude', TYPES.Float, decodeMessage.longitude);
request.addParameter('v_pos_altitude', TYPES.Int, (typeof (decodeMessage.altitude) != "undefined") ? decodeMessage.altitude : null);
request.addParameter('v_pos_speed', TYPES.Int, (typeof (decodeMessage.speed) != "undefined") ? decodeMessage.speed : null);
request.addParameter('v_pos_move', TYPES.Int, decodeMessage.move);
request.addParameter('v_pos_type', TYPES.Int, 1);
request.addParameter('v_pos_device', TYPES.VarChar, decodeMessage.device);
request.addParameter('v_pos_timestamp', TYPES.Int, decodeMessage.time);
request.on('doneInProc', function (rowCount, more, rows) {
intermediaryPositionSQL(decodeMessage, connection);
});
connection.execSql(request);
} else {
intermediaryPositionSQL(decodeMessage, connection);
}
}
此代码应该只是第一次使用 SQL 请求插入,然后使用新值再次执行
错误是:
error: RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state
这是我的 Azure SQL Server 的配置:
var config = {
userName: '***@***',
password: '*******',
server: '******.database.windows.net',
options: {encrypt: true, database: '******'}
};
我尝试了 doneProc,row,甚至没有成功完成。doneProc 犯了与 doneInProc 相同的错误,并且不会调用 row / done。