tags:

views:

50

answers:

1

I am using following code to connect to MySql Db but it gives error. please help me

"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified "

string ConnStr = @"Driver={MySQL ODBC 3.51 Driver};" +
               "Server=192.168.100.10/phpmyadmin/;Database=piggylock;uid=root;pwd=htroot;option=3";



    using(OdbcConnection con = new OdbcConnection(ConnStr))
    using(OdbcCommand cmd = new OdbcCommand("SELECT * FROM product", con))
    {
        con.Open();
        newslist.DataSource = cmd.ExecuteReader(
        CommandBehavior.CloseConnection |
        CommandBehavior.SingleResult);
        newslist.DataBind();
    }
+2  A: 

In general you should use the native ADO.Net MySql drivers available here: http://dev.mysql.com/downloads/connector/net/6.2.html. These offer much better performance and support more features than the generic ODBC driver.

Your error is in the connection string. Did you set up an ODBC data source on your computer? The ODBC driver needs this to connect.

Rune Grimstad
There are three should i install all or any specific(mysql-connector-net-6.2.2-noinstall.zip)(mysql-connector-net-6.2.2-src.zip)(mysql-connector-net-6.2.2.zip)
Azhar
It depende. The -scr one is the source code in case you want to compile your own. The -noinstall is just a zipped version if you want to store the files in a folder of your choice. The last one is the installer - this is the version most people download I suppose.
Rune Grimstad
thanks its working now
Azhar