473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 8140
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
5
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open,...
21
by: Sender | last post by:
I have two questions: (1) I just want to check whether a .txt file is empty or not (without opening it). Like I click on a command button then it should give message EMPTY if is empty and show...
2
by: Suma | last post by:
Hi To open a notepad file, right now I am using Process.start. But this does not ensure that the file is opened in readonly mode How can I make a notepad file open in Readonly mode I do not...
3
by: Jennifer | last post by:
On an ASP page I've got some code that is supposed to "export" data in a grid to an Excel file. What I'm doing is writing all the data to a text file, separating the fields by commas. Then I'll...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
18
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that...
2
by: RobcPettit | last post by:
Hi, Im using streamwriter to write to notepad or word. No problems with this. Is it possible to write to either notpad or word, while the document is open, and the data to update as its written....
2
by: connor_a | last post by:
Hi everyone, I want the user to be able to click a button on my website that creates a new text file, writes to it and then runs notepad to display the text file. How can this be coded on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.