Sunday 15 July 2012

c# - BackgroundWorker with MySql not working properly -


I have a way that mysql is for the loop in the database .

The amount of inclusion can be very high, so my program is freezing while inserting.

That's why I call it BackgroundWorker , although it is not working in schematic form ...

After getting some insert, I get an exception That my connection has already been opened

How do I do this here:

  if (dbPos.conn open ()) {// contains a line , Then works fine because the data is present in DB DBipes. Checkout (Pries, Y); // It works for some inserts, // but after a couple it will tell me that my cone is already an open worker. RunWorkerAsync (); // Insert multiple rows} dbPos.connClose ();   

My Backgroundworker method:

  zero worker _dovor (object sender, doWorkEventArgs e) {for (int i = 0; I & lt; chartList.Count; i ++) {switch (this.countChart (i)) {... work ... // insert rows}}}   

and My method is to actually enter values ​​in the database:

 using  (MySqlCommand cmd = new MySqlCommand (query, conn)) ... ... parameter .... cmd.ExecuteNonQuery (); }   

So how can I solve this mysterious problem?

The problem is that you are closing your connection:

  If (dbPos.conn open ()) {// contains a row, works fine because the data db dbPos.checkOut (prijs, wie); // This * start * works, but does not block the worker. RunWorkerAsync (); // inserts multiple rows} // This is when the background work is still happening dbPos.connClose ();   

You should call dbPos.connOpen () and connClose () in BackgroundWorker S DuvorX handler allows connections to remain open when this is done.

No comments:

Post a Comment