I have this code that I use for copy one table to another, but I got error while executing command statement.
Error says that connection is not open or valid. When I debug I can see it is opened.
Really don’t know why is not valid.
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con2"].ConnectionString;
con.Open();
cmd = new MySqlCommand("SELECT COUNT(*) FROM " + ConfigSettings.ReadSetting("main_base"), con);
int nRows = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (nRows > 0)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con1"].ConnectionString;
con.Open();
cmd = new MySqlCommand("INSERT INTO temp_data SELECT * FROM data");
cmd.ExecuteScalar();
}
Everything goes well until last command:
cmd = new MySqlCommand("INSERT INTO temp_data SELECT * FROM data");
cmd.ExecuteScalar();
Is this even possible if these two database are on different servers? Maybe I need to have two connections opened at the same time or something like that?
Pass the connection object to the
MySqlCommandconstructor: