sql - 快速路由错误“Err: TypeError: Cannot read property 'type' of undefined”
问题描述
我有注册用户的基本路线,它运行一个存储过程检查电子邮件是否存在于我的 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 应该是大写字母)。
希望这可以帮助!
推荐阅读
- ios - 如何使用 RxSwift 模拟 tableView 行选择
- ios - FACEBOOK 登录:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序
- php - 使用 csv 在列中设置数据
- npm - 如何在 NPM 脚本中使用 Windows 控制台“设置”变量?
- asp.net - 我们使用 SQL Server 2008 在 vs 2010 中开发了 asp.net mvc 3 Web 应用程序
- c# - 在 PKCS7 (CMS) 中使用相同的响应 xml 签名签署多个位置
- c# - 如何配置 NSubstitute 不调用内部虚拟方法
- html - 里面的进度元素html文本
- r - 对大于 0 的数字取对数时产生的 NaN
- php - 2个字段的验证Laravel:第一个是日期选择器,第二个是选择