0

I want to use MYSQL server with my asp.net application. But i am not able to connect to it. I am getting error that is "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified " .

My code is:-

 System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=new_testdb; User=root;Password=abc123#;");
    cn.Open();

    System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand();

    System.Data.Odbc.OdbcDataAdapter adp = null;

    DataSet ds = new DataSet();

    cmd.Connection = cn;

    cmd.CommandText = "Select * from new_table";

    adp = new System.Data.Odbc.OdbcDataAdapter(cmd);

    adp.Fill(ds, "new_table");

    this.GridView1.DataSource = ds;

    this.GridView1.DataMember = "new_table";

    cn.Close();
2
  • Did you install the MySQL ODBC 3.51 Driver? Commented Dec 15, 2011 at 10:25
  • i don't know i have installed only MYSQL server.. is it some different than that? Commented Dec 15, 2011 at 10:30

5 Answers 5

1

Try to download ADO.NET MySql Connector API (managed MySql Data provider) instead of ODBC Driver.

EDIT: Connector/NET Examples

Sign up to request clarification or add additional context in comments.

2 Comments

@raman - Then don't use Odbc. Add the reference of MySql.Data.Dll in your project and use classes from MySql.Data.MySqlClient namespace.
can you provide me any link that will helpful to me because i am new to MYSQL. I didn't try this server with asp.net so.
1

You also may connect to MySQL with dotConnect for MySQL components.

Try to build the connection string with MySqlConnectionStringBuilder class.

Comments

0

This is what you need: http://dev.mysql.com/downloads/connector/net

Enjoy!

Comments

0

Could you please see here My SQL ConnectionString or ConnectionString

Comments

0
  1. Click Left btn on database in server explorer, select properties copy connection string;

2.string c= persistsecurityinfo=True;server=localhost;user id=root;password=admin;database=sam;

  1.         MySqlConnection cn = new MySqlConnection(c);
    
            cn.Open();
            Response.Write("Connection successful !!");
            MySqlDataAdapter Mda = new MySqlDataAdapter("select * from tblName", cn);
            DataSet ds = new DataSet();
            Mda.Fill(ds, "tblName");
            GridView1.DataSource = ds.Tables["tblName"];
            GridView1.DataBind();
    
  2. Make sure that :-

    using System.Data;

    using MySql.Data.MySqlClient;

imported... :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.