Hello, I'm trying to write Windows app to get data from From Fox Pro DB, and inset it to Sql Server 2008 db.
I wrote code, but it works very slow. rowsCount more than 1 million My code below:
OleDbConnection cn = new OleDbConnection(foxProConnectionString);
SqlConnection cSql = new SqlConnection(sqlServerConnectionString);
cSql.Open();
OleDbCommand ocmd = new OleDbCommand("Select * from " + table, cn);
OleDbDataAdapter sda = new OleDbDataAdapter(ocmd);
DataTable dt = new DataTable();
sda.Fill(dt);
SqlCommand mySqlcmd = new SqlCommand();
mySqlcmd.Connection = cSql;
for (int i = 0; i < dt.Rows.Count; i++)
{
mySqlcmd.CommandText = "INSERT INTO sqlTable (column1, column2, column3) VALUES ("+dt.Rows[i][dt.Columns.IndexOf("column1")] + ",'"
+ DoOper1(dt.Rows[i]dt.Columns.IndexOf("column2")]) + "','"
+ dt.Rows[i][dt.Columns.IndexOf("column3")] + "')";
mySqlcmd.ExecuteNonQuery();
}
I cant use bulk copy, database columns order may be different in some source tables. Also I get error:
The CLR has been unable to transition from COM context 0x54afe8 to COM context 0x54b158 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
how can I solve a set of my problem?