Is it possible to setup ASP.NET MVC 2 to work with a MySQL database?
NET Core and MySQL are both free and open source technologies. The new ASP.NET Core can run on Linux and in Linux Containers, and MySQL is one of the easiest databases to get started with. This makes the combination of ASP.NET Core and MySQL a pretty compelling combination.
Click on the Create button and it will update the Index view as well add this new record to the database. Now let's go the SQL Server Object Explorer and refresh the database. Right-click on the Employees table and select the View data menu option. You will see that the record is added in the database.
Connect Database to MVC Application using Entity Framework Create a new project of ASP.NET MVC 5 web application using Visual Studio.NET 2015. Now, to connect a database to MVC 5 application using Entity Framework, the following three components must be added to MVC application, Database Model. Database Controller.
I'm assuming that you have Visual Studio Professional 2008, have access to an instance of MySQL server, and have moderate to advanced development experience. This MAY work with VS2008 Web edition, but not at all sure.
Modify the connection strings portion of your web.config:
<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>
8.
Modify the membership portion of your web.config:
<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>
9.
Modify the role manager portion of your web.config:
<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>
10.
Modify the profile portion of your web.config:
<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>
At this point, you ought to be able to run the app and have the default ASP.NET MVC 2 home page come up in your browser. However, it may be a better idea to first run the ASP.NET Web configuration Tool (in Visual Studio top menus: Project -> ASP.NET Configuration). Once the tool launches, check out each of the tabs; no errors = all good.
The configuration tool at Nathan Bridgewater's blog was essential to getting this working. Kudos, Nathan. Look for the "Configuration Tool" heading half way down the page.
The public key token on the MySql.web.dll that I've posted here ought not change any time soon. But in case you suspect a bad token string from copying and pasting or whatever, just use the Visual Studio command line to run: "sn -T [Path\to\your.dll]" in order to get the correct public key token.
There you have it, ASP.NET MVC 2 running over MySQL. Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With