Search code examples
mysqlasp.net-mvcasp.net-mvc-4asp.net-membership

How to use MVC membership provider with MySQL?


I'm currently working on an ASP.NET MVC web application. I used this tutorial to use MySqlMembershipProvider in the app. The required tables are also created in the MySql database:

MySqlMembershipProvider tables

Now, when I try to register as a new user in my application, I get this error:

Unknown column 'Extent1.UserName' in 'field list'

Exception Details: MySql.Data.MySqlClient.MySqlException: Unknown column 'Extent1.UserName' in 'field list'

Source Error:

Line 80:             {
Line 81:                 var user = new ApplicationUser() { UserName = model.UserName };
//error comes here at line 82
Line 82:                 var result = await UserManager.CreateAsync(user, model.Password);
Line 83:                 if (result.Succeeded)
Line 84:                 {

Solution

  • The error message shows that a query is being run which expects a field that it cannot find. So, the first thing to check is whether your my_aspnet_users table contains a UserName field. If not, then some error has occurred when the table was created.

    If the field does exist, check your membership connection string and make sure it is connecting to the right database.