When I attempt to pull data from the database I am getting zero results although my parameter is correct.
From my index.js where CustID is a parameter
app.get('/contacts', (req, res) => {
actions.getConts(req.params.CustID).then((data) => {
res.json(data[0]);
})
})
From my operations.js with GetContNT being a stored procedure on the server
async function getConts(CustID) {
try {
let pool = await sql.connect(db);
let contList = await pool.request()
.input('CustID', sql.NVarChar, CustID)
.execute('GetContNT');
return contList.recordsets;
}
catch (error) {
console.log(error);
}
}
module.exports = {
getConts: getConts,
}
If I run the stored procedure by itself on the SQL Server I get results.
If I replace the parameter with the text value, I get results.
With the parameter I get [] ... no results
I tried replacing the procedure call .execute('GetContNT'); directly with a query
.query("SELECT * FROM Contacts WHERE CustID = @CustID");
but got the same results.
Appreciate your help.
[email protected]against SQL Server 2022. Have you double checked thedbconfig object to confirm that it's connecting to the correct server, instance and database?console.dir(contList.recordsets)to confirm that it's completely empty. i.e.: if your stored procedure performs any delete/insert/update operations before it performs the select operation then Node will be seeing record counts with empty results for each of those data modification operations. Try insertingSET NOCOUNT ON;at the beginning of your stored procedure to see if it makes a difference.