views:

503

answers:

2

Creating a default ASP.NET MVC project in Visual Studio sets up a basic project where you can register a user. How would I go on changing this to use a MySQL server instead of SQLServer ?

+1  A: 

You can either implement (and replace the default) membership provider with one that works with MySQL or you can pull out the code that uses the membership provider and implement the membership functionality in your own code. I'd suggest that implementing a membership provider isn't too difficult and will make it easier. See the MSDN article on implementing membership provider for details.

tvanfosson
+1  A: 

Got it working now.

  • Install the latest Connector/NET (v 6.0.4.0 currently)
  • Replace the default connection string in web.config with something like:

    <add name="ApplicationServices" connectionString="server=192.168.1.30;user id=thsuser;Password=thepass;database=thedatabase" providerName="MySql.Data.MySqlClient"/>

  • Under the section in web.config add the following (for the 6.0.4.0 mysql connector atleast), add

    <add autogenerateschema="true" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

  • Run the project, go back into Visual Studio and click the ASP.NET Configuration button above the solution explorer.

    Navigate to "Provider Configuration"->"Select a different provider for each feature " and select the "MySQLMembershipProvider"

Works atleast for registering and logging in from a mysql database, the MySQLMembershipProvider will autogenerate the needed tables.

nos