Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
mssql node - Transaction rolled back still updating database

My database is SQL Server and I'm trying to use mssql npm package. Issue I'm facing here is, if I have a rejected promise, I was hoping my transaction to rollback, which I'm doing in the catch. But for some reason, my database is being updated.

const transaction = new sql.Transaction();
  try {
    await transaction.begin();
    let q1;

    if (shippingExists) {
      q1 = await updateShippedQuery();
    } else {
      q1 = await insertShippedQuery();
    }

    const q2 = await editWorkOrderQuery();

    const q3 = await addNoteQuery();

    const q4 = await editProductQuery();

    const q5 = new Promise((resolve, reject) => {
      setTimeout(reject, 100, { error: "Delibrate error" });
    });
   
    const [query1, query2, query3, query4, query5] = await Promise.all([
      q1,
      q2,
      q3,
      q4,
      q5,
    ]);
    await transaction.commit();
    return { query1, query2, query3, query4, query5 };
  } catch (e) {
    await transaction.rollback();
    console.log(e);
    return { error: e.message };
  }
};

Example of one function looks like this:

const sql = require("mssql");

const editProductQuery = async () => {
  const query = `
    UPDATE product 
    SET available_quantity = 4
    WHERE part_number = '10000'
  `;
  return await sql.query(query);
};

module.exports = editProductQuery;

What should be done here?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!