[英]Webmatrix.WebData.WebSecurity with MySql is not working. Throwing sql syntax error in WebSecurity.UserExists() check
I had a project done in MSSQL. 我有一个用MSSQL完成的项目。 I migrated MSSQL to MySql because i thought Webmatrix.WebData will support MySql also. 我将MSSQL迁移到MySql,因为我认为Webmatrix.WebData也将支持MySql。 WebSecurity initialiation was successful. WebSecurity初始化成功。
if (!WebSecurity.Initialized)
{
securityService.Initialize(
"sqlserver",
"UserProfile",
"UserId"
"UserName");
};`
Above code executed successfully. 以上代码成功执行。 But if fails to execute the following part, 但是如果无法执行以下部分,
if (!WebSecurity.UserExists("user"))
{
WebSecurity.CreateUserAndAccount("user", "password");
}
The check WebSecurity.UserExists("user")
is failing. 检查WebSecurity.UserExists("user")
失败。 This is the error message- 这是错误消息-
An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll but was not handled in user code MySql.Data.dll中发生类型为'MySql.Data.MySqlClient.MySqlException'的异常,但未在用户代码中处理
Additional information: You have an error in your SQL syntax; 附加信息:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '[UserId] FROM [UserTable] WHERE (UPPER([UserName]) = UPPER('user'))' at line 1 检查与您的MySQL服务器版本相对应的手册,以在第1行的'[UserId] FROM [UserTable] WHERE(UPPER([UserName])= UPPER('user'))'附近使用正确的语法
Please help me with this issue. 请帮我解决这个问题。
The WebSecurity shipped with ASP.Net (The one used in your code above) has some Microsoft T-SQL syntax embedded in the code. ASP.Net附带的WebSecurity(上面的代码中使用的一种)在代码中嵌入了一些Microsoft T-SQL语法。 There are little differences between the MySQL syntax and MSSQL which probably accounts for the error. MySQL语法和MSSQL之间几乎没有区别,这可能是导致错误的原因。
From the error shown, I can see the CreateUserAndAccount
method in WebSecurity somehow attempts to a execute the T-SQL statement .... [UserId] FROM [UserTable] WHERE (UPPER([UserName]) = UPPER('user'))
however, while this would work in MSSQL, the square brackets "["
and "]"
would cause errors in MySQL. 从显示的错误中,我可以看到WebSecurity中的CreateUserAndAccount
方法以某种方式试图执行T-SQL语句.... [UserId] FROM [UserTable] WHERE (UPPER([UserName]) = UPPER('user'))
但是,尽管这在MSSQL中有效,但方括号"["
和"]"
会导致MySQL错误。
A work around will be to use MySql.Web.Security.MySqlWebSecurity.CreateUserAndAccount("user", "password")
, of cause,you can add a using
statement or use it that way. 解决方法是使用MySql.Web.Security.MySqlWebSecurity.CreateUserAndAccount("user", "password")
,原因是,您可以添加using
语句或以这种方式使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.