关于连接问题或数据库关闭的 OracleException
OracleException with respect to Connection issues or Database down
假设我有关注query
private void updateusers()
{
List<int> listRecords=new List<int>();
string strQuery="select * from table where role='Admin' and logged_in<=sysdate-1";
OracleCommand com=new OracleCommand(strQuery,objConnection);
OracleDataReader reader=com.ExecuteReader();
if(reader.HasRows)
{
while(reader.read())
{
listRecords.Add(int.Parse(reader["Row_ID"].toString()));
}
int i=0;
foreach(int row in listRecords)
{
try
{
OracleCommand command=new OracleCommand();
command.Connection=objConnection;
command.CommandText="Update table set Status='Y' where Row_ID="+listRecords[i];
command.CommandType=System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch(OracleException ex)
{
//log the exception
}
}
}
}
现在我的问题是,让我们假设 select 查询获取 2000 条记录并且 foreach
将继续更新每个 record
并假设在第 500 record
数据库连接丢失 或 数据库因某种原因关闭。现在在这些场景中,我想迭代或尝试更新同一条记录 3 次,如果第三次失败,则退出 foreach-loop
并停止执行 update
命令以剩余 1500 条记录。
So is there any particular way to identify these type of Oracle Exceptions or better say Environmental exceptions? Does
OracleException
provide any particular messageCode
for these type
of exceptions?
您可以使用 ErrorCode
属性 of OracleException
class 来识别特定类型的错误。
假设我有关注query
private void updateusers()
{
List<int> listRecords=new List<int>();
string strQuery="select * from table where role='Admin' and logged_in<=sysdate-1";
OracleCommand com=new OracleCommand(strQuery,objConnection);
OracleDataReader reader=com.ExecuteReader();
if(reader.HasRows)
{
while(reader.read())
{
listRecords.Add(int.Parse(reader["Row_ID"].toString()));
}
int i=0;
foreach(int row in listRecords)
{
try
{
OracleCommand command=new OracleCommand();
command.Connection=objConnection;
command.CommandText="Update table set Status='Y' where Row_ID="+listRecords[i];
command.CommandType=System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch(OracleException ex)
{
//log the exception
}
}
}
}
现在我的问题是,让我们假设 select 查询获取 2000 条记录并且 foreach
将继续更新每个 record
并假设在第 500 record
数据库连接丢失 或 数据库因某种原因关闭。现在在这些场景中,我想迭代或尝试更新同一条记录 3 次,如果第三次失败,则退出 foreach-loop
并停止执行 update
命令以剩余 1500 条记录。
So is there any particular way to identify these type of Oracle Exceptions or better say Environmental exceptions? Does
OracleException
provide any particularmessageCode
for these type of exceptions?
您可以使用 ErrorCode
属性 of OracleException
class 来识别特定类型的错误。