Asem
Asem

Reputation: 21

How to connect Mysql server with Asp.net 2008

How to connect Mysql server (free one) with Asp.net 2008.

Upvotes: 0

Views: 1273

Answers (1)

Asem
Asem

Reputation: 21

I found the answer...
We need to install some components before creating connection string which is the main task. The following are the components that need to be installed.

  1. MYSQL connector
    http://dev.mysql.com/downloads/connector/net/5.0.html

  2. Microsoft Data Access Components (MDAC) 2.8
    http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en

After a successful installation of MySQL and MySQL Connector we can move to your project. Go to Visual Studio >> Solution Explorer >> Add references and add a reference to MySQL.DATA from .net components.

Then the following code can be included in our C# code for the connection.

public partial class _Default : System.Web.UI.Page
{
    private string strProvider = "Data Source=localhost;Database=mydatabse;User 
       ID=root;Password=a";
    protected void Page_Load(object sender, EventArgs e)
    {
        MySqlConnection objMyCon = new MySqlConnection(strProvider);
        objMyCon.Open();
      //Connection succeed and open..

    }
}

And we also need to import the following namespaces:

using System.Data.Odbc;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

The user ID will be always “root” and password is the Password which we provided while installing MYSQL. Here many new user will struck.

Asem Ibo.

Upvotes: 2

Related Questions