|
|
@@ -17,7 +17,7 @@ namespace UAS_MES.DataOperate
|
|
|
public static string DBConnectionString;
|
|
|
public static OracleConnection connection = null;
|
|
|
OracleCommand command = null;
|
|
|
-
|
|
|
+ int ReconnectTime = 0;
|
|
|
/// <summary>
|
|
|
/// 执行构造函数的时候打开数据库的链接
|
|
|
/// </summary>
|
|
|
@@ -58,6 +58,7 @@ namespace UAS_MES.DataOperate
|
|
|
string sql = "select " + Field + " from " + TableName + " where " + Condition;
|
|
|
Console.WriteLine(sql);
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
+ command.CommandTimeout = 60000;
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
ad.Fill(dt);
|
|
|
@@ -155,6 +156,7 @@ namespace UAS_MES.DataOperate
|
|
|
sql += " from " + TableName + " where " + Condition + " and rownum=1";
|
|
|
Console.WriteLine(sql);
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
+ command.CommandTimeout = 60000;
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
@@ -232,6 +234,7 @@ namespace UAS_MES.DataOperate
|
|
|
sql += " from " + TableName + " where " + Condition;
|
|
|
Console.WriteLine(sql);
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
+ command.CommandTimeout = 60000;
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
@@ -575,6 +578,7 @@ namespace UAS_MES.DataOperate
|
|
|
{
|
|
|
object result = null;
|
|
|
command = new OracleCommand(SQL, connection);
|
|
|
+ command.CommandTimeout = 600000;
|
|
|
//用来拼接参数的
|
|
|
if (names.Length > 0)
|
|
|
{
|
|
|
@@ -606,9 +610,24 @@ namespace UAS_MES.DataOperate
|
|
|
{
|
|
|
case "SELECT":
|
|
|
result = new DataTable();
|
|
|
- OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
- ad.Fill((DataTable)result);
|
|
|
- ad.Dispose();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
+ ad.Fill((DataTable)result);
|
|
|
+ ad.Dispose();
|
|
|
+ //成功执行后将重复连接数置为0
|
|
|
+ ReconnectTime = 0;
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ if (ReconnectTime == 0)
|
|
|
+ {
|
|
|
+ //重置的数据库链接后只执行一次
|
|
|
+ ReconnectTime = ReconnectTime + 1;
|
|
|
+ connection = new OracleConnection(DBConnectionString);
|
|
|
+ result = ExecuteSql(SQL, Type, names);
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
case "DELETE":
|
|
|
result = command.ExecuteNonQuery();
|