Node.js mssql package select query cache problem

Viewed 19

I try to retrieve data from SQL Server using npm mssql package. When I used postman to make a request, I got same data (resultset) at every time although data was changed.

My SQL Server connection config and code is here:

   const sql = require('mssql');
     const config = {
     user: 'XXXX',
     password: 'XXXX',
     server: 'XXXX',
     database: 'XXXX',
     pool: {
        max: 50,
        min: 0,
        idleTimeoutMillis: 10
      },
    options: {
        trustServerCertificate: true
    }
}

 const getConnection = async () => {
            try {
                const conn = await sql.connect(config);
                return {pool: conn, err: false, errorMSG: null};
            } catch (err) {
                return {conn: null, err: true, errorMSG: err}
            }
        };

And my db function :

 const conn = await getConnection();

    if (conn.err == false) {
        try {
            let result = await conn.pool.request()
                .input('registryNumber', sql.NVarChar(50), registryNumber)
                .input('password', sql.NVarChar(50), password)
                .query('SELECT role FROM [OperatorLogin].[dbo].[TBL_users]' +
                    'WHERE [TBL_users].[registryNumber] = @registryNumber AND [TBL_users].[password] = @password AND [TBL_users].[isActive] = 1 ')
            if (result.rowsAffected[0] >= 1) {
                return { Execution: true, ExecutionCode: 1, ExecutionMessage: "Record is available", ExecutionData: result.recordset }
            }
            else {
                return { Execution: true, ExecutionCode: 2, ExecutionMessage: "No records", ExecutionData: "" }
            }
        }
        catch (err) {
            return { Execution: false, ExecutionCode: -1, ExecutionMessage: "DB pool request error : " + err, ExecutionData: "" }
        }
    }
    else {
        return { Execution: false, ExecutionCode: -1, ExecutionMessage: " DB error : " + conn.errorMSG, ExecutionData: "" }
    }

On the other hand, I use pm2 and reverse proxy on Windows server.

What may be problem ? What am I missing ?

0 Answers
Related