3

I want to use MySQL with my Asp.Net application and would like to know how. I am going to use MySQL for the first time. The most important thing I would like to know is how to connect to a MySQL database.

3 Answers 3

7

You can use the following connectionstring in your web.config to connect to mysql database:

<connectionStrings>
  <add name="MySQLConnStr" connectionString="DRIVER={MySQL ODBC 3.51 Driver};Database=YourDatabase;Server=localhost;UID=YourUsername;PWD=YourPassword;"/>
</connectionStrings>

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 following will perfectly explain to you the architecture of ODBC: ODBC

And for more details go through following referenced articles:

Connect to MySQL database from ASP.NET

An ASP.NET Application Using a MySQL Database (Sample Application)

ASP.NET with MySQL - Getting started

Connector/NET Examples

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to use MySql connector API to establish the connection, execute queries and retrieving results. Take a look at tutorials.

3 Comments

can we connect a mysql server using remote access
ohk what will be the process to connect.
@RamSingh - Read and learn from the tutorial (link at post). Have a look at connection strings = connectionstrings.com/mysql
0

try downloading this http://www.devart.com/dotconnect/mysql/ this is a great tool and easy to connect mysql to ASP.net but t his is trail version

and then jst drop the components on the form/page

sample code

 using Devart.Data.MySql; 

  MySqlConnection conOne = new MySqlConnection("user id=root;password=root;host=localhost;database=studentDB");
string quePrvLT = "select rollna from studentTAble where rollna =" +res;
MySqlCommand cmdPLT = new MySqlCommand(quePrvLT, con);
int leaPLdB = (float)cmdPLT.ExecuteScalar();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.