开发者

How to connect Mysql server with Asp.net 2008

How to connect Mysql server (free one) with Asp.net开发者_Python百科 2008.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜