node-sqlserver, Azure Mobile Services and Azure SQL - old rows are returned even after transaction commit -
i have following code on server side:
let query = ` begin transaction foo_tran exec sp1_update ..., exec sp2_insert ..., exec sp3_update ..., exec sp4_delete ..., ... commit transaction foo_tran select 1 [@@@]; `; mssql.query(query, params, { success: function (res) { if (res && res.length === 1 && res[0]['@@@'] == 1) { response.status(200).send({id: request.body.id}); } }, error: (err)=>response.status(500).send(err) });
then client requests modified content using provided id
.
problem: old data returned ~2-3 seconds. tried specify read uncommited
in subsequent select, didn't - old rows mixed new ones.
to use transactions azure mobile services you'll want use open
method on mssql
connection supports transactions. see documentation of open method here. example:
request.service.mssql.open({ success: function(connection) { //start transaction connection.begintransaction(function(errtransaction) { if (errtransaction) { //handle error , respond error connection.close(); return; } //define querystring , queryparams connection.query(querystring, queryparams, function(errquery, results) { if (errquery) { //handle error , respond error connection.rollback(); connection.close(); return; } //success connection.commit(); connection.close(); //respond ok }); }); }, error: function(erropen) { //handle error } });
Comments
Post a Comment