R
RSH
Hi all,
I have a situation where I am looping through a DataTable and extracting
values from that DataTable and inserting them into a SQL database. The
application works fine but now I want to add an exception log to the
application. So, I added an Exception handling routine that basically has a
running string that adds errors to the string if they happen. I have three
questions:
1. If a SQL exception happens I would like it to write it to the
ErrorString and then continue to the next record (kind of like the old
Resume Next in VB).
2. When the application finishes running and there is an error in the error
string I would like to write the error to a text file in the application
path and then open the file using NotePad.exe.
3. How do I find the Application Path?
Exception Handling Code Excerpt:
catch (Exception e)
{
strError += "[DATA TRANSFER ERROR][Error: " + e.Message + "][Record Number:
" + iGlobalRecordProgress + "]";
// Resume Next
}
At the end of the application I detect if an error has occured:
if (strError.Length > 1)
{
TextWriter tw = new StreamWriter("DataImportErrorLog-" + DateTime.Now +
".txt");
tw.WriteLine(strError);
tw.Close();
DialogResult result = MessageBox.Show("Errors occurred during the data
transfer. Would you like to view the Error Log now?", "Confirm",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.OK)
{
// Open Error Log file with Notepad.exe
}
How do I go about that?
Thanks!
Ron
I have a situation where I am looping through a DataTable and extracting
values from that DataTable and inserting them into a SQL database. The
application works fine but now I want to add an exception log to the
application. So, I added an Exception handling routine that basically has a
running string that adds errors to the string if they happen. I have three
questions:
1. If a SQL exception happens I would like it to write it to the
ErrorString and then continue to the next record (kind of like the old
Resume Next in VB).
2. When the application finishes running and there is an error in the error
string I would like to write the error to a text file in the application
path and then open the file using NotePad.exe.
3. How do I find the Application Path?
Exception Handling Code Excerpt:
catch (Exception e)
{
strError += "[DATA TRANSFER ERROR][Error: " + e.Message + "][Record Number:
" + iGlobalRecordProgress + "]";
// Resume Next
}
At the end of the application I detect if an error has occured:
if (strError.Length > 1)
{
TextWriter tw = new StreamWriter("DataImportErrorLog-" + DateTime.Now +
".txt");
tw.WriteLine(strError);
tw.Close();
DialogResult result = MessageBox.Show("Errors occurred during the data
transfer. Would you like to view the Error Log now?", "Confirm",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.OK)
{
// Open Error Log file with Notepad.exe
}
How do I go about that?
Thanks!
Ron