I want to insert 100k rows into a SQL Server database using node. I have tried it using bulk method of request object but it will not working for me.
My function to insert into SQL Server database:
var startInsert = function(recordset) {
sql.connect(config,function(err) {
// console.log(recordset);
if(err){
console.log(err);
}
var table = new sql.Table('ShipmentAuditLogTest');
recordset.forEach(function(row) {
table.rows.add(row.ShippingID,row.BagNo,row.ProcessLocation,row.Process,row.Comment,row.CreatedDate,row.CreatedBy,row.LastModifiedDate,row.LastModifiedBy,row.DestinationLocation,row.VenderLostShipmentsDebitId);
});
var request = new sql.Request();
request.bulk(table, function(err, rowCount) {
console.log(table);
if(err)
console.log(err);
console.log(rowCount);
});
});
}
This will return this error:
{ [RequestError: Incorrect syntax near ')'.]
name: 'RequestError',
message: 'Incorrect syntax near \')\'.',
code: 'EREQUEST',
number: 102,
lineNumber: 1,
state: 1,
class: 15,
serverName: 'FCCHAKANDB',
procName: '',
precedingErrors: [] }
My recordset:
[ RowDataPacket {
ShippingID: '2FX880141',
BagNo: 'CHKXFL1808362',
ProcessLocation: '2',
Process: 'BagIn',
Comment: 'Shipment added in ParentBagNo: CHKXFL1808362',
CreatedDate: Tue Apr 07 2015 16:36:18 GMT+0530 (India Standard Time),
CreatedBy: 'support@firstcry.com',
LastModifiedDate: '0000-00-00 00:00:00',
LastModifiedBy: 'null',
DestinationLocation: 'null',
VenderLostShipmentsDebitId: 0,
InsertedTime: Mon Dec 14 2015 14:26:16 GMT+0530 (India Standard Time) } ]