Connect to MySQL database from ASP.NET

Connecting from ASP.NET to MySQL database is relatively easy. MySQL is a database server which is very popular and frequently used for web application backend. Most people with Windows background will wonder why you would use MySQL instead of MS SQL Server when using ASP.NET. The answer is that MySQL can do the same job as MS SQL Server for small to medium traffic website, but just for fraction of the cost or even for free.

Iíve explained below how to connect to MySQL from ASP.NET. We will connect to our MySQL database from ASP.NET using ODBC .NET data provider and DSN-less connection. You need to do the following before attempting to connect from ASP.NET to MySQL database:

1. Make sure you have installed the .Net Framework on your server 
2. Download the ODBC .Net data provider and install it on your development machine or your server. You can download it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=6ccd8427-1017-4f33-a062-d165078e32b1&DisplayLang=en
3. install MySQL ODBC Driver-MyODBC 3.51. You can download it here: http://dev.mysql.com/downloads/connector/odbc/3.51.html 

The ASP.NET code below connects to a MySQL database and displays all the records from Users table.

<%@ Page CompilerOptions='/R:"C:\Program Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"'%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.Odbc" %>








As I told you connecting between ASP.NET and MySQL was easy. Both ASP.NET and MySQL are great technologies and they are free to use, which make them appealing to a broad software and web development audience.


SQL Strings Home | SQL Server connection strings | MS Access connection strings | MySQL connection strings | Oracle connection strings | Database Glossary | MySQL PHP Connection | MySQL Perl Connection | MS Access ASP Connection | MS SQL Server ASP Connection | MySQL ASP.NET Connection | MySQL ASP Connection