I’ve been googling all day to find out how to use the ASP.NET Login Controls with MySQL. And finaly I did it. I’m sharing this knowledge here.

Firstly I’ve installed Mysql.Data 5.2.2 (version 5.2.3 doesn’t auto generate schema). You can download it from here.

Add connection string in your web.config file for the database connection:

<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer" connectionString="server=localhost; user id=root; password=pwd; persist security info=true; database=your_database;" providerName="MySql.Data.MySqlClient"/>
</ connectionStrings>

I have copied dll’s from MySql Program Files folder Mysql.Data and Mysql.Web into my application’s Bin folder and refreshed the Solution Explorer from Visual Studio.

Then edited my machine.config file and added autogenerateschema=”true” attribute at this line:

<membership>
<providers>
<add name="MySQLMembershipProvider" autogenerateschema="true" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=5.2.2.0, ... />
</providers>
</membership>

Finaly opened my ASP.Net Site Configuration (With the web site project loaded in Visual Web Developer, select Website › ASP.NET Configuration). Selected MySQLMembershipProvider from Membership Provide’s list and MySQLRoleProvider from Role Provider at Provider Tab. You can also do a test if the connection is ok.

I had these errors during the learning process :

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem: Unable to initialize provider. Missing or incorrect schema. (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 145)

You could also see these pages. They got really helpfull to me:

www.dotnetsurfers.com
blog.nolanbailey.com
forums.asp.net