Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何获得';完成';批量插入完成后的消息?_Sql_Sql Server_Node.js - Fatal编程技术网

Sql 如何获得';完成';批量插入完成后的消息?

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

我正在尝试使用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.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
函数上使用回调,如中所述:


就像另一个答案一样,这似乎解决了我的问题,谢谢!就像另一个答案一样,这似乎解决了我的问题,谢谢!