While attempting to utilize the .bulk
operation within the node-mssql
library in node.js, an error message is being returned:
While reading current row from host, a premature end-of-message was encountered--an incoming data stream was interrupted when the server expected to see more data. The host program may have terminated. Ensure that you are using a supported client application programming interface (API)
// the issue arises when calling this function
export async function insert(
transaction: sql.Request,
data: any[],
) {
const table = prepare(data);
return await transaction.bulk(table);
}
function prepare(data: any[]) {
const table = new sql.Table('dbo.SomeTable');
table.create = false;
table.columns.add('MyColumn1', sql.Int, { nullable: false });
table.columns.add('MyColumn2', sql.Int, { nullable: false });
table.columns.add('MyColumn3', sql.Int, { nullable: false });
for (const mov of data) {
table.rows.add(
mov.field1,
mov.field2,
mov.field3
);
}
return table;
}