473,729 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
" + iGlobalRecordPr ogress + "]";

// Resume Next

}
At the end of the application I detect if an error has occured:

if (strError.Lengt h > 1)

{

TextWriter tw = new StreamWriter("D ataImportErrorL og-" + DateTime.Now +
".txt");

tw.WriteLine(st rError);

tw.Close();

DialogResult result = MessageBox.Show ("Errors occurred during the data
transfer. Would you like to view the Error Log now?", "Confirm",
MessageBoxButto ns.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 8170
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:
" + iGlobalRecordPr ogress + "]";

// Resume Next

}
At the end of the application I detect if an error has occured:

if (strError.Lengt h > 1)

{

TextWriter tw = new StreamWriter("D ataImportErrorL og-" + DateTime.Now +
".txt");

tw.WriteLine(st rError);

tw.Close();

DialogResult result = MessageBox.Show ("Errors occurred during the data
transfer. Would you like to view the Error Log now?", "Confirm",
MessageBoxButto ns.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.Curre ntDomain.BaseDi rectory

for execution see System.Diagnost ics.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
6418
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 points = 123 @@@begin data@@@ gibberish follows.....
5
714
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, FileAccess.ReadWrite, FileShare.None); which does not prevent me from opening the file even if another user has the file open ie Notepad, it will prevent me from saving the file in notepad until i close the file in the app. I can then save changes made in...
21
13012
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 message "NON EMPTY" if it is not empty. (2) What are the steps to open a notepad file (C:\XYZ\abc.txt) in a VB Text Box. Thanks
2
11162
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 want to change its attributes to Readonly I do not want to open it in browser or in any other editor except notepad I do not want to use MFCAppWizard of VC++ or VB to create my own editor. I do not want to paste the text in some richtextbox...
3
7022
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 redirect the user to a new page with the file that was just created. Code: Dim objFSO, objTextFile Dim sRead, sReadLine, sReadAll Const ForReading = 1, ForWriting = 2, ForAppending = 8
16
2204
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
18
6717
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 I've already created on my computer. Whenever I go to open the script file (whose icon shows that it's a SQL Server Query File and I've got the file type set to open with SQLWB - SQL Server Management Studio), the file opens in Notepad instead of...
2
2792
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. At the momment notepad has to be closed, saved and reopened to see the data. Word doesnt allow me to write to it whilst its open. Regards Robert
2
1858
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 client side? Works fine but only on server side at the moment. ;-) Thanks for any assistance.
0
8768
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9226
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3248
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2173
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.