【问题标题】:RequestError: Validation failed for parameter 'request_UserID'. Cannot read property 'validate' of undefinedRequestError:参数“request_UserID”的验证失败。无法读取未定义的属性“验证”
【发布时间】:2021-11-09 02:16:03
【问题描述】:

使用 NodeJS 从 MSSQL 中连接和选择记录太麻烦了

这是我的代码

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);
});

这是错误信息

RequestError:参数“request_UserID”的验证失败。无法读取未定义的属性“验证”

我研究了这个例子 - 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

在示例中,它们不使用参数进行查询。我需要使用参数来避免SQL注入

【问题讨论】:

  • 你试过TYPES.VarChar而不是TYPES.VARCHAR了吗?
  • 非常感谢@AlwaysLearning 成功了。

标签: javascript node.js sql-server database tedious


【解决方案1】:

解决方案是将 TYPES.VARCHAR 更改为 TYPES.VarChar

感谢@AlwaysLearning

【讨论】:

  • 向前付款 说“谢谢”是值得的,但它并不能回答问题。相反,请投票选出对您最有帮助的答案!如果这些答案对您有帮助,请考虑以更具建设性的方式表示感谢——通过对您的同行在这里提出的问题贡献您自己的答案。 How do I write a good answer
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多