简体   繁体   English

使用MySql的Webmatrix.WebData.WebSecurity无法正常工作。 WebSecurity.UserExists()检查中引发SQL语法错误

[英]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语句或以这种方式使用它。

see link 见链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在WPF应用程序中使用WebMatrix.WebData.WebSecurity - Using WebMatrix.WebData.WebSecurity in a WPF application WebMatrix.WebData.WebSecurity - 如何只通过PasswordResetToken获取UserName - WebMatrix.WebData.WebSecurity - How can I get UserName by only having PasswordResetToken WebMatrix中的WebSecurity的PasswordReset无法正常工作 - PasswordReset with WebSecurity in WebMatrix not working WebMatrix WebSecurity PasswordSalt - WebMatrix WebSecurity PasswordSalt WebMatrix剃须刀C#WebSecurity登录但Web.Security.IsAuthenticated没有返回正确的检查 - WebMatrix razor C# WebSecurity Logging in but Web.Security.IsAuthenticated not returning right check WebSecurity CreateUserAndAccount - WebSecurity CreateUserAndAccount 自定义简单成员资格/ WebMatrix Websecurity? 是否可以抑制OAuth表? 删除密码字段? - Customizing Simple Membership/WebMatrix Websecurity? Ability to suppress OAuth Tables? Delete password field? WebMatrix WebData InitializeDatabaseConnection - WebMatrix WebData InitializeDatabaseConnection WebSecurity.IsAuthenticated 如何检查您是否已登录? - How does WebSecurity.IsAuthenticated check if you're logged in or not? 如何检查WebSecurity“密码重置令牌ID”的有效性? - How to check WebSecurity 'Password Reset Token ID' validity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM