开发者

Error in Connecting with MySql with Asp.net

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();
    }


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜