I had a project done in MSSQL. I migrated MSSQL to MySql because i thought Webmatrix.WebData will support MySql also. WebSecurity initialiation was successful.
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. 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
Additional information: You have an error in your SQL syntax; 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
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. There are little differences between the MySQL syntax and MSSQL which probably accounts for the error.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.