Tyring to connect and Select record from MSSQL using NodeJS and tedious
Here is my code
connection.on("connect", function (err) {
sqlCommand = new Request(
"SELECT * FROM video.videoView WHERE Id = @Id AND CONVERT(VARCHAR(MAX), request_userID) = @request_UserID",
function (err) {
if (err) {
console.log(err);
}
}
);
sqlCommand.addParameter("Id", TYPES.UniqueIdentifier, data.vid);
sqlCommand.addParameter(
"request_UserID",
TYPES.VARCHAR,
data.email_address
);
sqlCommand.on("row", function (columns) {
columns.forEach(function (column) {
});
});
sqlCommand.on("requestCompleted", function (rowCount, more) {
connection.close();
});
connection.execSql(sqlCommand);
});
Here is the error message
RequestError: Validation failed for parameter 'request_UserID'. Cannot read property 'validate' of undefined
I looked into this example - https://docs.microsoft.com/en-us/sql/connect/node-js/step-3-proof-of-concept-connecting-to-sql-using-node-js?view=sql-server-ver15
In the example they do not query using parameters. I need to use parameters to avoid SQL injection
The solution was to change TYPES.VARCHAR to TYPES.VarChar
Thanks @AlwaysLearning