|
|
@@ -21,7 +21,7 @@ namespace UAS_LabelMachine
|
|
|
//富为外网地址
|
|
|
//private readonly string ConnectionStrings = "Data Source=richwellgroup.com.cn/orcl;User ID=DATACENTER;PassWord=select!#%*(";
|
|
|
//怡海能达外网地址
|
|
|
- private readonly string ConnectionStrings = "Data Source=sz.hi-mantech.com/orcl;User ID=DATACENTER;PassWord=select!#%*(";
|
|
|
+ private readonly string ConnectionStrings = "Data Source=sz.hi-mantech.com/orcl;User ID=YHND_SZ;PassWord=select!#%*(";
|
|
|
//怡海能达内网地址
|
|
|
//private readonly string ConnectionStrings = "Data Source=192.168.1.200/orcl;User ID=DATACENTER;PassWord=select!#%*(";
|
|
|
//用户选择的数据库的连接字符串
|
|
|
@@ -29,6 +29,10 @@ namespace UAS_LabelMachine
|
|
|
static OracleConnection connection = null;
|
|
|
static OracleCommand command = null;
|
|
|
/// <summary>
|
|
|
+ /// 重置连接的次数
|
|
|
+ /// </summary>
|
|
|
+ int ReconnectTime = 0;
|
|
|
+ /// <summary>
|
|
|
/// 执行构造函数的时候打开数据库的链接
|
|
|
/// </summary>
|
|
|
public DataHelper()
|
|
|
@@ -98,7 +102,22 @@ namespace UAS_LabelMachine
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
- ad.Fill(dt);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ad.Fill(dt);
|
|
|
+ ReconnectTime = 0;
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ if (ReconnectTime == 0)
|
|
|
+ {
|
|
|
+ ReconnectTime++;
|
|
|
+ connection = new OracleConnection(DBConnectionString);
|
|
|
+ //成功执行后将重复连接数置为0
|
|
|
+ dt = (DataTable)getFieldDataByCondition(TableName, Field, Condition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (dt.Rows.Count > 0)
|
|
|
{
|
|
|
ad.Dispose();
|
|
|
@@ -743,6 +762,7 @@ namespace UAS_LabelMachine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 直接执行SQL,同时传入SQL的类型
|
|
|
/// </summary>
|
|
|
@@ -790,11 +810,17 @@ namespace UAS_LabelMachine
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill((DataTable)result);
|
|
|
ad.Dispose();
|
|
|
+ //成功执行后将重复连接数置为0
|
|
|
+ ReconnectTime = 0;
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
- connection = new OracleConnection(DBConnectionString);
|
|
|
- result = ExecuteSql(SQL, Type, names);
|
|
|
+ if (ReconnectTime == 0)
|
|
|
+ {
|
|
|
+ ReconnectTime++;
|
|
|
+ connection = new OracleConnection(DBConnectionString);
|
|
|
+ result = ExecuteSql(SQL, Type, names);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case "DELETE":
|