Continous for loop query generates connection terminated unexpectedly?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Continous for loop query generates connection terminated unexpectedly?

    Dear All,
    I have an application where I have one central server and many other local servers. So from each one of the local or the central server I can actually move a number serials. So then in the same time I have cental table which keeps a record of each serial and where it is active now I mean in which of the servers. So the problem comes when I move a big number (around 600) of serial say from server A to server B. Then in server B I will receive all the transfered serials and run a for loop to check each of the serial agains the central table which is kept in the central server. The problem is when serial number is small is ok but when it gets big I get the error connection terminated unexpectedly? I know is due to heave query so is there any solution to it ? Below is a snippet of my code.

    for (int j = 0; j < gridReceiveSerial.RowCount; j++)
    globalConnectionCentral1 myConnect1 = null;
    MySqlDataReader myReader1 = null;
    int serialExist = 0;
    myConnect1 = new globalConnectionCentral1();
    myConnect1.command.CommandText = "Select " +
    "tblCentral.serialID " +
    "From tblCentral" +
    "Where tblCentral.serialStatus ='y' And " +
    "tblCentral.serial='" + this.gridReceiveSerial[8, j].Value.ToString() + "'";

    myReader1 = myConnect1.command.ExecuteReader();
    if (myReader1.HasRows == true)
    serialExist = 1;
    MessageBox.Show("this.gridReceiveSerial[8, j].Value.ToString() + " " + "Exist");
    catch (MySql.Data.MySqlClient.MySqlException ex)
    MessageBox.Show("Connection Error" + ex.Message);