Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continous for loop query generates connection terminated unexpectedly?

Status
Not open for further replies.

newtomysql

Technical User
Apr 11, 2001
96
MY
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;
try
{
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");
}
else
{
}
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Connection Error" + ex.Message);
}

finally
{
myReader1.Close();
myConnect1.command.Dispose();
myConnect1.connection1.Close();
}
}
 
Can you print the sql statement to the screen or alert box. Not sure what language this is in...looks like some M$ language. Maybe add another messagebox to show the sql.

How is the field configured? Text, BIGINT? What are the indexes?

Mark
 
Dear Kozusnik,
I am using C#. I have tried to print the sql statemtents using the message box but after sometimes I do get the error too. The field of tblCentral.serial is a varchar of length 20. Anything else I should provide to help solve my problem ? Can it be due to time out problem? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top