I'm trying to call a register stored procedure from SQL Server. I'm using NodeJS with the mssql package. I got most of the code from the mssql Npm documentation. But it still doesn't work.
The code basically tries to initiate a ConnectionPool as a read the last update renamed connection to ConnectionPool, create a new request, introduce the parameters and the execute the stored procedure. I have it this way because I need to change the connection variable to another database every once in a while.
The error I get is:
ConnectionError: Connection is closed.
My code:
const sql = require('mssql');
const config = require('../config/dbPoly');
module.exports.registerUser = function(pUserName, pPassword, pNombre, pApellidos, pFK_TipoUsuario, callback) {
var connection = new sql.ConnectionPool(config);
var request = new sql.Request(connection);
request.input('input_parameter', sql.VARCHAR(25), pUserName);
request.input('input_parameter', sql.VARCHAR(16), pPassword);
request.input('input_parameter', sql.VARCHAR(25), pNombre);
request.input('input_parameter', sql.VARCHAR(50), pApellidos);
request.input('input_parameter', sql.Int, pFK_TipoUsuario);
request.execute('RegistrarUsuario', (err, result)=>{
if(err){
console.log(err);
}
else{
console.log(result);
}
});
};