This article describes how my blog uses ADO to access SQL Server to get data. This chapter describes how to use my SQL to complete data management.
Before using my SQL, you need to ensure that the my SQL database and connector/net are installed in the development environment, which is an ADO data provider written in C #, in other words, whether you use SQL Server or my sql,asp. NET is to access, manipulate the database through ADO, the only difference is the data provider, so the connection to my SQL still needs to use the type in System.Data.dll, the following is described in the previous article:
The only difference is that the My SQL ADO data provider is required to install connector/net.
installing my SQL and connector/net
connector/net:https://dev.mysql.com/downloads/windows/installer/
MySQL (You can choose to install connector/net directly at installation): https://dev.mysql.com/downloads/mysql/
Add data tables and data when finished:
Create a new warehousing project for my SQL
The reason for creating a new project for it is to have SQL Server coexist with my SQL, which does not affect each other, and can be used to switch the database for use by simple modifications later on.
1. Create a new Class library project Blogrepository.mysql, and reference mysql.data (note: mysql.data need to install connector/net):
2. Implement a blogrepository using the Execute SQL method:
Compared to the code in SQL Server, only the object names, SQL, and connection strings differ.
3. Change the reference to the logical layer, use blogrepository.mysql, and modify the wrong namespace:
4. Run the program:
Summary:
This chapter describes how to use the MySQL database in ASP, which is basically the same as SQL Server, just install the components you need to connect to my SQL. Another point to note is that there are now blogrepository and blogrepository.mysql two repositories in the entire solution, respectively, for SQL Server and my SQL but only one for the logical layer, This means that each time you replace the database business logic library, you need to change not only the reference but also the code. This is a typical dependency implementation without relying on abstraction. This issue will be followed by a workaround.
Reference:
Https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting.html
This article connects: http://www.cnblogs.com/selimsong/p/7655042.html
Asp. NET no magic--Directory
Asp. NET no magic--asp.net MVC and database MySQL