我有一种使用WebSecurity.CreateUserAndAccount(model.UserName, model.Password)
注册新用户的方法问题是在UserProfile
模型中我添加了GUID
密钥。在我的本地机器上,当我调用此方法时,这只会填充一个空的Guid。然而,在azure上,我收到以下错误:
System.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'Key', table 'Scheduler.dbo.UserProfile'; column does not allow nulls. INSERT fails.
现在,我试图在模型的构造函数中生成一个新的GUID,手动让Set{}
生成一个新的GUID,我得到同样的错误。
当我尝试使用CreateUserAndAccount重载时:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Key = Guid.NewGuid() });
我收到以下语法错误(运行时):
Incorrect syntax near the keyword 'Key'.
我早上花了大部分时间试图解决这个问题,而我却做不到。顺便说一句,上述所有方法仍然会导致空GUID 00000000-0000-0000-0000-000000000000
,并且重载会在本地计算机上出现语法错误。
答案 0 :(得分:0)
“Key”是SQL中的保留字,它应该在括号中使用,如[Key]
由于您无法控制WebSecurity如何生成SQL查询,因此您唯一的选择是将其重命名为UserKey