I am not at all familiar with ASP.NET membership/roles. This is my first time using it, and my first time trying ASP.NET MVC. When I create my first project for MVC, it gives me a lovely template to create an account. I was excited to see that I did not have to do this manually. However, it failed because it cannot connect to SQL Server. I do not have SQL Server, I have MySQL. Is there any easy way I can get this system to use MySQL instead, or will I have to create my own authentication?
6 Answers
Got it figured out! Using version 6.2.2.0 of MySql Connector/Net, follow these steps...
- Add reference to MySql.Web.dll
Change your
<membership>
in web.config to this:<membership defaultProvider="MySqlMembershipProvider"> <providers> <clear/> <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" autogenerateschema="true" connectionStringName="NAME_OF_YOUR_CONN_STRING" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" /> </providers> </membership>
- Run the Project | ASP.NET Configuration tool and click on the Security tab to test
- Tested on ASP.NET 3.5, MySQL Server version 5.1, Windows XP 64-bit

- 81,538
- 47
- 180
- 227
-
Thanks. This was a great help. Don't miss off adding the defaultProvider! – Kildareflare Mar 31 '13 at 23:16
The original question didn't specify which version of ASP.NET & MVC was used. With the recent release of .NET 4.5 and MVC 4 I hit the same problem as the OP but with the new technologies. This is my quick fix for it mostly the same config as Josh Stodola's answer but with some additional steps.
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear />
<add name="MySqlMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider,
MySql.Web, Version=6.5.4.0, PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"
connectionStringName="*NAME_OF_YOUR_CONN_STRING*"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/" />
</providers>
</membership>
Get the AccountController and Views working:
- Delete the MVC 4 AccountController, AccountModels, Account view folder and _LoginPartial shared view
- Create a new MVC 3 web application
- Copy the MVC 3 AccountController, AccountModels, Account view folder and _LogOnPartial shared view into your MVC 4 application
- Replace
@Html.Partial(“_LoginPartial”)
in the shared _Layout view with@Html.Partial(“_LogOnPartial”)

- 2,848
- 1
- 21
- 30
In my scenario, I do not need to connect to MySQL from my .NET web applications. Therefore, I solved this problem by doing two things:
1) Uninstall MySQL .NET Connector (all versions) 2) Inside the Web.Config file, remove all keys that were added after the MySQL installation. (Or else, copy back the original Web.Config file before installation to the .NET web application root folder)
Now, my .NET application is bac
Had to go through something similar.
Here's the official MySql walkthrough that helped me:
Tutorial: MySQL Connector/Net ASP.NET Membership and Role Provider
Note: In my case, the machine.config
to be edited was the 32 bit one (they didn't specify which, and editing the 64bit one didn't help).

- 11,507
- 3
- 43
- 82
I've did this with asp.net but I think it could be used for mvc too: hasangursoy.com.tr/aspnet-authorization-authentication-with-mysql

- 12,734
- 29
- 100
- 154
Click on the menu Project followed by ASP.NET Configuration.
That will create the sql database for you in the Data folder.
Use Visual Studio to look at the data.
Hope this helps.
Edit
I should add that you can then use Ctrl+Alt+S to see the Server Explorer which should then allow you to see your database with its tables and the data.
You shouldn't need SQL installed.

- 22,624
- 33
- 128
- 205
-
I got the tool to finally come up (it is slower than molasses), but I don't see any database. I went to security tab, and tried to select a data store. Then it gives me a list of providers, but only one is there (AspNetSqlProvider), but this gives me the same error (cannot connect to SQL server). – Josh Stodola Jan 10 '10 at 23:11
-
In visual studio can you now see the aspnetdb.mdf file? It should be in the App_Data folder. Ensure you are showing all files. – griegs Jan 10 '10 at 23:16
-
1
-