Connect to MYSQL database from C# 2005 express IDE

Does anyone know how to add MYSQL to the list of datasources you can connect to in Visual C# express 2005 Right now all that is in there is SQL Server and Access. Thanks.



Answer this question

Connect to MYSQL database from C# 2005 express IDE

  • Ti-Tim-Timmy

    With the IDE there is no way to connect to any other database system using the wizards, this is one of the restrictions on the Express editions. One way that I have seen this done though is to create a Data Layer and use that. By this I mean that you would connect to the database in code and do the processing, but publish the DataSets as Objects (There is a good example of this in the Person Web Site Starter Kit, I know it is Web but the principles are the same).

    For the connection string for MySQL you might want to have a look at the following site it has heaps of different connection strings for almost all of the known Database Engines.

    http://www.connectionstrings.com/



  • FlavioOliveira

    Thanks guys, appreciate the help, I was hoping their was a way to use the IDE just for a visual cause I am new to database programming. Leave it to microsoft to not allow the competition in on their IDE.

  • Ragz

    Well, seeing how you're using the MySQL .NET framework provider (and not ODBC), your connection string should consist of one or more of:

    AllowBatch
    AllowZeroDateTime
    CacheServerConfig
    CharacterSet
    ConnectionLifetime
    ConnectionTimeout
    ConvertZeroDateTime
    Database
    Logging
    MaxPoolSize
    MinPoolSize
    Password
    PersistSecurityInfo
    PipeName
    Pooling
    Port
    Protocol
    ResetPooledConnections
    Server
    SharedMemoryName
    UseCompression
    UseOldSyntax
    UserId

    You should consult the MySQL team to find out the meaning of each of these parameters. 



  • Lan Lan

    Thanks so much. I found the code already maybe i share with you guys hope it helps to those who have the same problems.

    Can refer to here:

    http://forums.mysql.com/read.php 38,91399,91518#msg-91518

    using MySql.Data.MySqlClient; // please go to mysql and download .net connector to use this.

    MySqlConnection oMySqlConn = new MySqlConnection();

    oMySqlConn.ConnectionString = "server=server; database=db; user id=uid; Pwd=passwd; pooling=false;";

    try

    {

    oMySqlConn.Open();

    if (oMySqlConn.State == ConnectionState.Open) MessageBox.Show("Connection to MySQL opened through OLE DB Provider");

    oMySqlConn.Close();

    }

    catch (MySqlException ex)

    {

    MessageBox.Show (ex.Number + " - " + ex.Message,"DB-Connection");

    }


  • Kristoffer Ryden

    Although you won't be able to use the Express C# IDE to edit the database through Server Explorer (ask Microsoft for the reasons), you can still connect to it programmatically. Oh by the way, do you know the ODBC connection string to use to connect to MySQL via ODBC

    using System.Data.Odbc;
    using System.Data;

    private void GetDataFromSQL()
    {
    string connStr =
    "Driver={SQL Native Client};Server=localhost\\sqlexpress;" +
    "Database=oshahsdb;Trusted_Connection=yes;"
    ;
    /** Yes, I know this is the connection string for SQL2005, But that's because my
    * database is SQLExpress, and not MySQL. Anyway, it's near trivial to change the
    *
    connection string so it connects to MySQL instead!
    **/

    using
    (OdbcConnection odbcCon = new OdbcConnection(connStr))
    using (OdbcCommand odbcCom = new OdbcCommand("Select * From Product", odbcCon))
    using (OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom))
    using (DataSet ds = new DataSet())
    {
    odbcCon.Open();
    odbcDA.Fill(ds);
    /** Now that we have it in a DataSet, we can do what you want with it: Parse it into
    * a business object, dump it into XML, set it as a DataSource for one of your controls...
    **/
    this.dataGridView1.DataSource = ds.Tables[0];
    }

    }

    Let us know if it helps.



  • dybarra

    With the help of mysql connector documentation and a link by you i have came up with something but it seems that it does not work can someone help

    using MySql.Data.MySqlClient;

    MySqlConnection oMySqlConn = new MySqlConnection();

    oMySqlConn.ConnectionString = Server=server;Database=database;Uid=username;Pwd=asdhjgasd;";

    try {

    oMySqlConn.Open();

    if (oMySqlConn.State == ConnectionState.Open) MessageBox.Show("Connection to MySQL opened through OLE DB Provider");

    oMySqlConn.Close();

    } catch (Exception ex) {

    MessageBox.Show(ex.Message);

    }

    the one in orange and bold needs to change.


  • LeProgrammeur

    go to http://dev.mysql.com/tech-resources/articles/dotnet/

    here you will find a host of providers to connect with MySQL. use the apporiate provider to connect to mysql database.



  • Henrik Erlandsson

    Cough, cough... mark answers cough, cough...

    You may also want to try buying the higher editions of visual studio. These editions are able to connect to datasources other than Access and SQL server files (some designers are also available in VWD Express).

    The reason VWD Express is allowed to connect to other databases is that ASP.NET web sites would be pretty useless without a database .



  • Connect to MYSQL database from C# 2005 express IDE