Running a stored procedure with NodeJS and MSSQL package error
I don't know if this would be helpful or not but this is how I did
let executeQuery = async (value, country) => {
try {
let pool = await sql.connect(dbConfig);
let results = await pool.request()
.input('input_parameter', sql.Int, value)
.input('Country', sql.VarChar(50), country)
// .output('output_parameter', sql.VarChar(50))
.execute('procedure_name')
console.dir(results);
} catch (err) {
res.json({
"error": true,
"message": "Error executing query"
})
}
}
executeQuery(value, country);
I've used async and await method to make it more readable.
I think the line's
req.input('ProductEntryID', req.Int, 3299);
req.input('LoginEntryID', req.Int, 4);
req.input('TempLoginEntryId', req.Int, -1);
req.input('AddToWishList', req.Bit, 0);
req.input('WebPortalId', req.Int, 0);
which has req.input thats wrong it seems.
Please try this code
var sql = require('mssql');
var config = {
user: 'sa',
password: '---',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: 'Test'
}
var getCities = function() {
var conn = new sql.Connection(config);
conn.connect().then(function(conn) {
var request = new sql.Request(conn);
request.input('City', sql.VarChar(30), 'Cbe');
request.input('NameNew', sql.VarChar(30), 'Cbe');
request.execute('spTest').then(function(err, recordsets, returnValue, affected) {
console.dir(recordsets);
console.dir(err);
}).catch(function(err) {
console.log(err);
});
});
}
getCities();
I tried this myself and its giving the results.