|
@@ -26,14 +26,7 @@ namespace parkMonitor.Database2
|
|
|
MySqlDataReader reader = null;
|
|
|
int garageFreeSpace = 0;
|
|
|
string sql = "select * from garage where garageID = '" + garageID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -56,10 +49,13 @@ namespace parkMonitor.Database2
|
|
|
Console.WriteLine("车位剩余数查无结果");
|
|
|
}
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "查询剩余车位异常");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -67,8 +63,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
- }
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return garageFreeSpace; ;
|
|
@@ -84,14 +79,7 @@ namespace parkMonitor.Database2
|
|
|
Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where garageID = '" + garageID + "' ";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -117,11 +105,14 @@ namespace parkMonitor.Database2
|
|
|
lps.Add(ps.parkingSpaceID, (Parking_Space)ps.Clone());
|
|
|
}
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
return lps;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "查询车位表异常");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -129,8 +120,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
- }
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -146,14 +136,7 @@ namespace parkMonitor.Database2
|
|
|
Vehicle v = new Vehicle();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -177,14 +160,17 @@ namespace parkMonitor.Database2
|
|
|
v.parkingSpaceID = parkingSpaceID;
|
|
|
v.garageID = garageID;
|
|
|
v.frontwheelbase = frontwheelbase;
|
|
|
- v.rearwheelbase = rearwheelbase;
|
|
|
- return v;
|
|
|
+ v.rearwheelbase = rearwheelbase;
|
|
|
}
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ return v;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "查询车辆表异常");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -192,8 +178,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
- }
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -209,14 +194,7 @@ namespace parkMonitor.Database2
|
|
|
Parking_Space ps = new Parking_Space();
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -235,14 +213,17 @@ namespace parkMonitor.Database2
|
|
|
ps.parkingSpaceID = parkingSpaceID;
|
|
|
ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
|
|
|
ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
|
|
|
- ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
- return ps;
|
|
|
+ ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
|
|
|
}
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ return ps;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "查询车位表获取x,y,z异常");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -250,8 +231,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
- }
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -266,14 +246,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isTelRegister = false;
|
|
|
string sql = "select * from user where userTelephone = '" + tel + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -293,14 +266,13 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
isTelRegister = false;
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "检测电话号码注册异常");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
}
|
|
|
return isTelRegister;
|
|
@@ -316,14 +288,7 @@ namespace parkMonitor.Database2
|
|
|
int parkingRecordsID = 0;
|
|
|
MySqlDataReader reader = null;
|
|
|
string sql = "select parkingRecordsID from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -346,10 +311,13 @@ namespace parkMonitor.Database2
|
|
|
Console.WriteLine("停车记录id查无结果");
|
|
|
}
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "查询停车记录id异常");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -357,8 +325,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
reader.Close();
|
|
|
reader.Dispose();
|
|
|
- }
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return parkingRecordsID;
|
|
@@ -375,14 +342,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isNumberPlate = true;
|
|
|
string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -402,14 +362,13 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
isNumberPlate = false;
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "检测车库中车辆异常");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
}
|
|
|
return isNumberPlate;
|
|
@@ -424,14 +383,7 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
bool isNumberPlateFromVehicle = true;
|
|
|
string sql = "select * from vehicle where numberPlate = '" + numberPlate + "' and vehiclepParkState = 1";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -451,14 +403,13 @@ namespace parkMonitor.Database2
|
|
|
{
|
|
|
isNumberPlateFromVehicle = false;
|
|
|
}
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "检测车辆表车辆号牌异常");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
}
|
|
|
return isNumberPlateFromVehicle;
|
|
@@ -472,23 +423,25 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateVehicleParkState(BlockingQueue bq, string numberPlate, int vehiclepParkState)
|
|
|
{
|
|
|
string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "'where numberPlate = '" + numberPlate + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message+"更新车辆状态失败");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -500,23 +453,25 @@ namespace parkMonitor.Database2
|
|
|
public void UpdateParkingSpaceState(BlockingQueue bq, int parkingSpaceID, int parkingSpaceState)
|
|
|
{
|
|
|
string sql = "update parkingspace set parkingSpaceState = '" + parkingSpaceState + "'where parkingSpaceID = '" + parkingSpaceID + "'";
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
- object result = access.GetResult();
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(sql, conn, CommandTypes.NOQUERYCOMMAND);
|
|
|
+ object result = access.GetResult();
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message+"更新车位状态失败");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -528,14 +483,7 @@ namespace parkMonitor.Database2
|
|
|
public static int InsertParkingRecords(BlockingQueue bq, List<string> strs)
|
|
|
{
|
|
|
int parkingRecordsID = 0;
|
|
|
- Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- int i = 0;
|
|
|
- while (conn == null && i < 2)
|
|
|
- {
|
|
|
- ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
- conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
- i++;
|
|
|
- }
|
|
|
+ Connection conn = CreateConnAndGetValidConn(bq);
|
|
|
if (conn == null)
|
|
|
{
|
|
|
Console.WriteLine("请检查网络!等待网络修复超时");
|
|
@@ -543,18 +491,17 @@ namespace parkMonitor.Database2
|
|
|
else
|
|
|
{
|
|
|
DBAccess access = new DBAccess(null, conn, CommandTypes.TRANSACTIONCOMMAND);
|
|
|
- TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
+ TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
try
|
|
|
{
|
|
|
parkingRecordsID = transactionResult.result;
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message + "停车记录ID获取失败");
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
}
|
|
|
}
|
|
|
return parkingRecordsID;
|
|
@@ -571,6 +518,7 @@ namespace parkMonitor.Database2
|
|
|
int i = 0;
|
|
|
while (conn == null && i < 2)
|
|
|
{
|
|
|
+ Console.WriteLine("为从连接池获取连接--------->UpdateTransaction" + i);
|
|
|
ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
i++;
|
|
@@ -581,9 +529,19 @@ namespace parkMonitor.Database2
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DBAccess access = new DBAccess(null, conn, CommandTypes.TRANSACTIONCOMMAND);
|
|
|
- TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
- flag = transactionResult.flag;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DBAccess access = new DBAccess(null, conn, CommandTypes.TRANSACTIONCOMMAND);
|
|
|
+ TransactionResult transactionResult = access.DealTransaction(strs);
|
|
|
+ flag = transactionResult.flag;
|
|
|
+ ConnectionPoolManager.ReleaseConnection(conn, bq);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message+"更新事务失败");
|
|
|
+ conn.Dispose();
|
|
|
+ ConnectionPoolManager.AddConnToPooling(1, ConnectionPoolManager.remoteConf);
|
|
|
+ }
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
@@ -696,5 +654,59 @@ namespace parkMonitor.Database2
|
|
|
// }
|
|
|
// return result;
|
|
|
//}
|
|
|
+
|
|
|
+ private static Connection CreateConnAndGetValidConn(BlockingQueue bq)
|
|
|
+ {
|
|
|
+ Connection conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ int i = 0;
|
|
|
+ while (conn == null && i < 2)
|
|
|
+ {
|
|
|
+ Console.WriteLine("为从连接池获取连接--------->InsertParkingRecords" + i);
|
|
|
+ ConnectionPoolManager.CheckConnPooling(2, 10, ConnectionPoolManager.remoteConf, bq);
|
|
|
+ conn = ConnectionPoolManager.GetConnection(bq, TIMEOUT);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void KillTimeOutConnection(string ip, int TimeOut, BlockingQueue bq)
|
|
|
+ {
|
|
|
+ object result = null;
|
|
|
+ string ipmohu = "'%" + ip + "%'";
|
|
|
+ string sql = null;
|
|
|
+ List<string> killidlist = new List<string>();
|
|
|
+ if (ip == null)
|
|
|
+ {
|
|
|
+ sql = "select concat('KILL ',id,';') from information_schema.processlist where Time > " + @TimeOut;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql = "select concat('KILL ',id,';') from information_schema.processlist where host like" + @ipmohu + " and Time >= " + @TimeOut;
|
|
|
+ }
|
|
|
+ DBAccess dba = new DBAccess();
|
|
|
+ dba.sql = sql;
|
|
|
+ dba.conn = CreateConnAndGetValidConn(bq);
|
|
|
+ dba.commType = CommandTypes.QUERYCOMMAND;
|
|
|
+ if (dba.conn != null)
|
|
|
+ {
|
|
|
+ result = dba.GetResult();
|
|
|
+
|
|
|
+ }
|
|
|
+ MySqlDataReader rdr = (MySqlDataReader)result;
|
|
|
+ while (rdr.Read())
|
|
|
+ {
|
|
|
+ killidlist.Add((string)rdr[0]);
|
|
|
+ }
|
|
|
+ rdr.Close();
|
|
|
+ foreach (string str in killidlist)
|
|
|
+ {
|
|
|
+ //Console.WriteLine(str);
|
|
|
+ dba.sql = str;
|
|
|
+ dba.commType = CommandTypes.NOQUERYCOMMAND;
|
|
|
+ dba.GetResult();
|
|
|
+ }
|
|
|
+ dba.conn.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|