Node.js mssql UPDATE Statements take > 1 minute to Execute

Node.js mssql update delays often stem from poor indexing, locking, or inefficient queries, requiring execution plan analysis and database optimization.

Summarize with AI

Not enough time? get the key points instantly.

Updating records in Microsoft SQL Server from a Node.js application is a common task. Using the mssql package you can execute UPDATE queries with parameterized inputs to avoid SQL injection.

Step 1: Install mssql Package

bash

npm install mssql

Step 2: Configure MSSQL Connection

js

const sql = require(‘mssql’);const config = {

user: ‘your_username’,

password: ‘your_password’,

server: ‘localhost’,

database: ‘your_db’,

options: {

encrypt: true, // Use for Azure

trustServerCertificate: true, // For local dev

},

};

Also Read: How to Do Base64 Encoding in Node.js

Step 3: Execute an UPDATE Query

js

async function updateUserEmail(userId, newEmail) {try {

let pool = await sql.connect(config);

await pool

.request()

.input(’email’, sql.VarChar, newEmail)

.input(‘id’, sql.Int, userId)

.query(‘UPDATE Users SET Email = @email WHERE Id = @id’);

console.log(‘Update successful’);

} catch (err) {

console.error(‘Update failed’, err);

}

}

This is type safe and SQL injection proof.

Conclusion

Now you know how to update SQL Server records from Node.js using mssql package with parameterized queries for security.


Resources

Insights from our engineering leaders.

Our team shares practical insights on the technologies and engineering decisions shaping enterprise software today, grounded in real client work.

NodeJS

Which Company Is Best for Hiring Node.js Developers in the UK?

Node.js helps businesses build backend systems, REST APIs, real-time applications, and SaaS platforms using JavaScript. Developing these solutions requires professionals who understand application architecture, technical…

NodeJS

How to tell if Node.js is installed or not?

To verify Node.js installation, run node -v or node --version. This checks if Node.js is installed and working correctly. Problem Before you run any Node.js…