I am using visual studio 2010 with mySql server , the connection in workbench is working properly but when i am trying to connect mysql in my application , it gives above error.
what is the reason behind it?
I am using following connection string to connect,
and below code to use it,con.ConnectionString = @"server=localhost;database=his_db;Uid=root;Pwd=root;persistsecurityinfo=True";
code:
cmd = new MySqlCommand("select distinct from_store_name from indent_details", con);
table = new DataTable();
adapter = new MySqlDataAdapter(cmd);
adapter.Fill(table);
foreach (DataRow row in table.Rows)
{
string frmstore = row["from_store_name"].ToString();
txtfromstore.Items.Add(frmstore);
}
解决方案The chances are that you need to remake your connection string: it may be that "localhost" is not the right designation from your PC.
Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.
Server=localhost;port=3306;pooling=false;Database=DBname;uid=root;pwd=";