I've got the following code where i'm basically taking data from mysql and plonking in SQL server.
The SQL server part works fine, but I can't work out how to keep the mysql connection open to do the update. When it does the mysql execute reader in the foreach loop it bums out with the error:
An unhandled exception of type 'System.InvalidOperationException' occurred in MySql.Data.dll
Additional information: Connection must be valid and open.
Code:
DB db = new DB();
String sConfig_hostname =
String sConfig_dbname =
String sConfig_dbusername =
String sConfig_dbpassword =
string MyConString = "SERVER=" + sConfig_hostname + ";" +
"DATABASE=" + sConfig_dbname + ";" +
"UID=" + sConfig_dbusername + ";" +
"PASSWORD=" + sConfig_dbpassword + ";Allow Zero Datetime=true;";
MySqlConnection connection = new MySqlConnection(MyConString);
string sQuery="Select * from inbox where Transferred = 0";
MySqlDataAdapter myDA = new MySqlDataAdapter(sQuery, connection);
MySqlCommandBuilder cmb=new MySqlCommandBuilder(myDA);
DataTable MyDT = new DataTable();
myDA.Fill(MyDT);
foreach (DataRow row in MyDT.Rows)
{
String SQL = String.Format("Insert into Inbox (Message, Received, Sender) VALUES ('{0}', '{1}', '{2}')", GeneralFunctions.SQLescape(row["TextDecoded"].ToString()), row["ReceivingDateTime"].ToString(), row["SenderNumber"].ToString());
String mySQL = "Update inbox set Transferred = 1 where ID = " + row["ID"].ToString();
db.Update(SQL);
MySqlCommand SQLup = new MySqlCommand(mySQL);
MySqlDataReader reader = SQLup.ExecuteReader();
}