bulk insert into temporary table without transaction wrapper *sometimes* returns "Invalid object name '#temp'."
See original GitHub issueI’ve submitted this along with https://github.com/tediousjs/node-mssql/issues/813
Expected behaviour:
Bulk insert of data into temporary table should be possible without a transaction.
Actual behaviour:
If I do not use a transaction with the request, the request fails some of the time with: “Invalid object name ‘#temp’.”. The rest of the time the request executes correctly.
Configuration:
db.config.json
{
"DB_DEV_SERVER": ... ,
"DB_TEST_SERVER": ... ,
"DB_PROD_SERVER": ... ,
"DB_DATABASE": ... ,
"DB_USER": ... ,
"DB_PASS": ... ,
"POOL_MAX": 20,
"POOL_MIN": 5,
"POOL_TIMEOUT": 3000
}
Software versions
- NodeJS: v8.11.3
- node-mssql: 4.3.2
- SQL Server: SQL Server 2012
Code to replicate issue:
router.get("/bugtest", async (req, res) => {
try {
const request = new sql.Request();
const temp = new sql.Table("#temp");
temp.create = true;
temp.columns.add("id", sql.Int, {nullable: false});
temp.rows.add( Math.random()*100|0 );
await request.bulk(temp);
const results = await request.query("select id from #temp;");
res.status("200").json({
success: true,
message: "Success.",
results: results
});
} catch (err) {
res.status("500").json({
success: false,
message: "Failure.",
err
});
}
});
This sometimes returns:
{"success":false,"message":"Failure.","err":{"code":"EREQUEST","number":208,"lineNumber":1,"class":16,"serverName":"...","procName":"","originalError":{"info":{"number":208,"state":0,"class":16,"message":"Invalid object name '#temp'.","serverName":"...","procName":"","lineNumber":1,"name":"ERROR","event":"errorMessage"}},"name":"RequestError","precedingErrors":[]}}
Other times it returns:
{"success":true,"message":"Success.","results":{"recordsets":[[{"id":81}]],"recordset":[{"id":81}],"output":{},"rowsAffected":[1]}}
And then if I execute rapidly, it returns:
{"success":true,"message":"Success.","results":{"recordsets":[[{"id":2},{"id":52}]],"recordset":[{"id":2},{"id":52}],"output":{},"rowsAffected":[2]}}
Which is too many rows. I’ve reported this last point as a seperate issue: https://github.com/tediousjs/node-mssql/issues/813
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
@dhensby Should the bulk insert examples in the readme be updated to reflect what you’ve said?
On second thoughts, I don’t think so because we don’t provide any docs around temp tables directly.