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!

Multiple different select statement in a for loop.

Status
Not open for further replies.

newtomysql

Technical User
Apr 11, 2001
96
MY
Dear All,
I got a list of product where based on a datareader I run a for loop. The based on each of the productID i do a number of select statement from various table around 24 different types of selects. So at some times my code give me an error saying that "unable to connect to any of the specified mysql hosts. So below is how my connection query looks like. I have tried to change to pooling=true the effect is quite the same. The error comes on a random basis sometimes during runing the 13th statement or 17th statement etc. So any solution for this type of multiples queries? I have 2 separate connection query one for the outler loop and one inner loop for each of the select statement once done I close and open the connection. Thanks.

public globalConnectionLocal2()
{
this.connection1 = new MySqlConnection("Address='localhost';Database='db1';User Name='root';Password='12345';Pooling='false'");
this.command = this.connection1.CreateCommand();
this.connection1.Open();
}

// destructor - explicitly
~globalConnectionLocal2()
{
this.command.Dispose();
this.connection1.Close();
this.connection1.Dispose();
}
 
This is a little unclear. Are you connecting to the same database or are they different based on some criteria?

Why are you opening and closing the connections inside of the loops? That seems inefficient.
 
Dear Darrellblackhawk,
No I am connecting to the same database. Why I am opening is because I need to run different queries on different tables. So infact I got a list of product and I run a for loop based on each productID.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top