471,319 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Writing an exception log an opening it with Notepad.exe

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
Dec 28 '05 #1
3 8065
Look at Process.Start

RSH wrote:
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

Dec 28 '05 #2
path: AppDomain.CurrentDomain.BaseDirectory

for execution see System.Diagnostics.Process
hope it helps

Dec 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by john smith | last post: by
5 posts views Thread by PM | last post: by
21 posts views Thread by Sender | last post: by
16 posts views Thread by iwdu15 | last post: by
2 posts views Thread by RobcPettit | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.