Sql 如何获得';完成';批量插入完成后的消息?
我正在尝试使用Node.js、mssql库和SQL Server在完成批量插入请求后运行函数:Sql 如何获得';完成';批量插入完成后的消息?,sql,sql-server,node.js,Sql,Sql Server,Node.js,我正在尝试使用Node.js、mssql库和SQL Server在完成批量插入请求后运行函数: sql.connect(config, function (err) { // error handling var request = new sql.Request() request.bulk(table, function (err, rowCount) { if (err) { // error handling } }) request.o
sql.connect(config, function (err) {
// error handling
var request = new sql.Request()
request.bulk(table, function (err, rowCount) {
if (err) {
// error handling
}
})
request.on('error', function (err) { // Doesn't Register
console.dir(err)
})
request.on('done', function (returnValue, affected) { // Doesn't Register
MyClass.MyFunction() // FUNCTION I NEED TO CALL
})
})
sql.on('error', function (err) {
// error handling
sql.close()
})
既不会触发错误,也不会触发“完成”事件。只有在SQL请求完成后,我才需要运行MyFunction
。为什么它没有触发事件 从中,您的请求将在.bulk()
回调中完成。不确定为什么不调用请求“done”事件,但请尝试使用批量回调
request.bulk(table, function (err, rowCount) {
if (err) {
// error handling
}
console.log('Bulk insert is done, %s rows committed', rowCount);
})
从中,您的请求将在.bulk()
回调中完成。不确定为什么不调用请求“done”事件,但请尝试使用批量回调
request.bulk(table, function (err, rowCount) {
if (err) {
// error handling
}
console.log('Bulk insert is done, %s rows committed', rowCount);
})
在
bulk
函数上使用回调,如中所述:
在
bulk
函数上使用回调,如中所述:
就像另一个答案一样,这似乎解决了我的问题,谢谢!就像另一个答案一样,这似乎解决了我的问题,谢谢!