Click here to Skip to main content
15,903,856 members

Comments by furynight8 (Top 4 by date)

furynight8 16-Oct-14 5:13am View    
I have tried to solve my problem by below approach.

bool endOfFile = !actionRtfReader.HasRows;
while (!endOfFile)
{
try
{
bool readResult = actionRtfReader.Read();
endOfFile = !readResult;
}
catch (Exception rowLevelException)
{
if (ex.Message.ToString().ToLower().Contains("connect"))
{
Environment.Exit(0);
}
else
{
MessageBox.Show(rowLevelException.GetType().ToString() + " : " + rowLevelException.Message);
}
}
}

I am checking whether the exception message contains "connect". If it contains "connect" , i am terminating my program.

Kindly advise me whether my approach is correct.
furynight8 16-Oct-14 5:11am View    
Deleted
I have tried to solve my problem by below approach.
furynight8 16-Oct-14 4:11am View    
Hi,

I am checking the connection while saving the details in DataReader. I have millions of records to be fetched from database. Since DataReader is a connected object, I am getting exception in each objDataReader.Read() statement. For example, say i have fetched around 5000 rows from database using the Read() statement and the connection to database is lost while fetching 5001 row.

There may be many exceptions while objDatareader.Read(), but only when the exception occurs due to connection lost, i have to terminate my program.

Kindly advice me how to proceed in this.
furynight8 16-Oct-14 3:53am View    
Hi All,

First of all, thanks a lot for all your replies.

I am having the below code in my application, to catch row level exceptions.

OracleCommand actionRtfCommand = new OracleCommand("select * from ACTION_RTF", conn);
actionRtfCommand.InitialLONGFetchSize = -1;
OracleDataReader actionRtfReader = actionRtfCommand.ExecuteReader();

// read only one record each roundtrip to avoid that exception has consequences for subsequent read statements
// (when the exception occurs the buffer becomes corrupted giving problems for subsequent read operations to the same buffer)
// Since this reduction of fetchsize (increasing number of roundtrips) has a significant performance penalty (typical fetchsize is 131072)
// it should only be applied when command involves LONG or LONG RAW columns
actionRtfReader.FetchSize = actionRtfReader.RowSize;

bool endOfFile = !actionRtfReader.HasRows;
while (!endOfFile)
{
try
{
bool readResult = actionRtfReader.Read();
endOfFile = !readResult;
}
catch (Exception rowLevelException)
{
// handle exception
MessageBox.Show(rowLevelException.GetType().ToString() + " : " + rowLevelException.Message);
}
}

DataReader will fetch only one row at a time and if any exceptions occurs while reading it will be caught in the exception.

Sometimes while executing the loop, the connection to the database is lost due to some reason. So only in condition when the connection to the database is lost, i have to terminate the program. In other conditions, it should work as it is working now.