Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 快速路由错误“错误:类型错误:无法读取未定义的属性“类型”_Sql_Node.js_Sql Server_Express - Fatal编程技术网

Sql 快速路由错误“错误:类型错误:无法读取未定义的属性“类型”

Sql 快速路由错误“错误:类型错误:无法读取未定义的属性“类型”,sql,node.js,sql-server,express,Sql,Node.js,Sql Server,Express,我有注册用户的基本路线,它首先运行一个存储过程检查电子邮件是否存在于我的SQL数据库中,然后运行一个存储过程更新记录(如果不存在) 然而,我不断地得到错误 Err: TypeError: Cannot read property 'type' of undefined 这是我的路线 app.post("/register", async (req, response) => { try { await sql.connect(config); const Emai

我有注册用户的基本路线,它首先运行一个存储过程检查电子邮件是否存在于我的SQL数据库中,然后运行一个存储过程更新记录(如果不存在)

然而,我不断地得到错误

 Err:  TypeError: Cannot read property 'type' of undefined
这是我的路线

app.post("/register", async (req, response) => {
  try {
    await sql.connect(config);
    const Email = req.body.email;
    const PasswordHash = req.body.password;
    const UserEmail = req.body.email;

    var request = new sql.Request();

    request.input("Email", sql.VarChar, Email);
    //request.input("Password", sql.VarChar, Password);

    const result = await request.execute("dbo.CheckEmailExists");

    if (result.recordsets[0].length > 0) {
      console.info("These credentials already exist");
      console.log(req.body);
    } else {
      console.info("these credentials do not exist well done");

      console.log({ UserEmail });
      request.input("UserEmail", sql.nVarChar, UserEmail);
      request.input("PasswordHash", sql.nVarChar, PasswordHash);
      request.execute("dbo.RegisterUser");

      console.log("done done");
    }
  } catch (err) {
    console.log("Err: ", err);
    response.status(500).send("Check api console.log for the error");
  }
});

为什么会发生这种情况?我该如何解决

ALTER PROCEDURE [dbo].[RegisterUser]
  @UserEmail nvarchar(320),
  @PasswordHash nvarchar(100)

  AS

  INSERT into RegisteredUsers (Email,PasswordHash) values (@UserEmail,  HASHBYTES('SHA2_512', @PasswordHash ))






它应该是sql。NVarChar N应该是大写的


希望这有帮助

顺便说一句,不管你的错误是什么,这实际上不是一个好方法,因为它在并发状态下是不安全的——网站本身就允许并行请求,这意味着电子邮件可以添加到对exists和register调用的调用之间。通常,最好使用事务一致性存储过程,如果用户尚未注册,则注册用户并返回结果?因为这是我最初尝试过的,但不知道如何暗示它,这可能是另一个问题的答案。在最基本的层面上,比如开始事务;使用HOLDLOCK从[users]中选择@id=id,其中。。。;如果@id为空,则开始;插入选择@id=SCOPE\u IDENTITY;犯罪为已注册的结果选择@id.Season with Extrace,使其具有附加列。它现在执行了一些操作,返回节点:17420 UnhandledPromisejectionWarning:RequestError:过程或函数RegisterUser指定的参数太多。很好,您现在可以对照路由器代码的参数交叉检查您在存储过程中定义的参数数量吗?您好,我已经更新了这个问题,它现在包含我的存储过程。我看不到问题您的请求有3个参数来自checkemail的Email,后来为registeruser添加了两个UserEmail和PasswordHash。