public void testLink()
{
int count = 0;
int intLength = 100;
MySqlConnection[] conn = new MySqlConnection[intLength];
MySqlCommand[] stmt = new MySqlCommand[intLength];
MySqlDataReader[] myReader = new MySqlDataReader[intLength];
try
{
string myConnectionString = "Server=192.160.10.130;UserId=root;Password=root;Database=camera";
for (count = 0; count < intLength; count++)
{
conn[count] = new MySqlConnection(myConnectionString);
string myInsertQuery = "Select * from t_pathinfo";
stmt[count] = new MySqlCommand(myInsertQuery);
stmt[count].Connection = conn[count];
conn[count].Open();
myReader[count] = stmt[count].ExecuteReader();
if (myReader[count].Read())
{
string strValue = myReader[count]["pathid"].ToString();
}
Console.WriteLine(count);
}
}
catch (Exception ex1)
{
throw new Exception(ex1.Message);
}
finally
{
try
{
count --;
for (; count >= 0; count--)
{
myReader[count].Close();
conn[count].Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
本文介绍了一个使用C#进行批量MySQL数据库查询的示例程序。该程序通过创建多个连接和命令对象,同时执行相同查询,旨在测试数据库链接和读取效率。每个查询从t_pathinfo表中选择所有记录,并读取pathid字段。
208

被折叠的 条评论
为什么被折叠?



