CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005
    Posts
    40

    c# connection to Mysql DB

    hej hej!!!

    i am totally confused in connecting to a MYSQL database using C#.Net.

    i created a mysql db by using the command line..under C:/mysql/data/example1

    now i open a new project in c# and want to connect to this db.

    there are lots of staff around and i am totally confused..
    some uses OLEDB some uses ODBC..what is the difference..
    which one to use for MYSQL..

    what should the connectionstring be??
    Acc. to http://www.connectionstrings.com/ it should be sth like;
    "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"

    this does not seem to work for me. it gives the error MySqlProv is not registered,(i installed Mic Data Access Components& ODBC .NET Data Provider & MYSQL Connector )

    and another question: where do we state that our database is C:/mysql/data/example1...
    is it ok if i just write Data Source=example1??

    i am totally confused my friends..any help will be greatly apreciated..
    and if possible can u show the code part that creates the string and the connection..

    thnk you all..the code i tried is a simple form application :

    ...

    using System.Data.OleDb;

    ...

    private void button1_Click(object sender, System.EventArgs e)
    {
    System.Data.OleDb.OleDbConnection con;

    string ConStr;

    ConStr = "Provider=MySQLOLEDB;Data Source=example1";

    con = new System.Data.OleDb.OleDbConnection(ConStr);

    try
    {
    con.Open();
    if (con.State==ConnectionState.Open) MessageBox.Show("Connection to MySQL opened through OLE DB Provider");
    con.Close();
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    }

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: c# connection to Mysql DB

    You should be using MySQL Connector rather than OLEDB or ODBC.

  3. #3
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: c# connection to Mysql DB

    and then you need to specify

    Code:
    DataSource=yourservername;Database=yourdatabase;UserName=yourusername;Password=yourpassword;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured