Say I have following 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
}
}
}
}
Now my problem is, Lets assume select query fetches 2000 records and foreach
will continue to update each record
and assume at 500th record
either DB connection is lost or say Database is down for some reason. Now in these scenarios I want to iterate or try updating same record for 3 times and if it fails 3rd time, come out of foreach-loop
and stop executing update
commands for remaining 1500 records.
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?
You can use ErrorCode
property of OracleException
class to identify particular type of error.