Home >Database >Mysql Tutorial >How can I configure ASP.NET MVC 2 to work with a MySQL database?
Using ASP.NET MVC 2 with MySQL Database
Certainly, it is possible to configure ASP.NET MVC 2 to work seamlessly with a MySQL database. Follow these steps:
Requirements:
Instructions:
Install MySQL Connector for .NET:
Install MVC 2:
Create MySQL Database:
Create MVC 2 Application:
Reference MySQL DLL:
Modify Connection Strings:
<code class="xml"><connectionStrings> <remove name="LocalMySqlServer"/> <add name="MySqlMembershipConnection" connectionString="Data Source=[MySql server host name]; userid=[user]; password=[password]; database=[database name];" providerName="MySql.Data.MySqlClient"/> </connectionStrings></code>
Configure Membership:
<code class="xml"><membership defaultProvider="MySqlMembershipProvider"> <providers> <clear/> <add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="MySqlMembershipConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true"/> </providers> </membership> </code>
Configure Role Management:
<code class="xml"><roleManager enabled="true" defaultProvider="MySqlRoleProvider"> <providers> <clear /> <add connectionStringName="MySqlMembershipConnection" applicationName="/" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" autogenerateschema="true"/> </providers> </roleManager></code>
Configure Profiles:
<code class="xml"><profile> <providers> <clear/> <add type="MySql.Web.Security.MySQLProfileProvider, MySql.Web, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" name="MySqlProfileProvider" applicationName="/" connectionStringName="MySqlMembershipConnection" autogenerateschema="true"/> </providers> </profile></code>
Testing:
To find the public key token string for MySQL.Web.dll, run the following command in the Visual Studio command line: "sn -T [Pathtoyour.dll]".
With these configurations in place, ASP.NET MVC 2 should seamlessly integrate with your MySQL database.
The above is the detailed content of How can I configure ASP.NET MVC 2 to work with a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!