Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

StreamReader reading appended lines

Posted on 2004-09-22
7
Medium Priority
?
289 Views
Last Modified: 2010-04-15
I have a windows service that read text from a file when this is created and insert that data into a SQL DB. There is no problem to do this. With a fileSystemWatcher I have resolved this.

Then this file is modified appending new data, and there is the problem. With the onchanged event I detect when this file is modified but, ¿is there any way to only read the new lines appended?

If I read all the file I create duplicated rows in the Sql and this way is not valid.

Thanks
0
Comment
Question by:EM77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Accepted Solution

by:
somnatic earned 128 total points
ID: 12121518
* Why not delete the rows passed to the DB from the file .. ?

* Store the number of the last row somewhere and then read from that row on only ..
0
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 124 total points
ID: 12121980
Instead of appending the lines to a existing file, Why don't u take a backup of this file and delete it. Then recreate the file with only the new lines. U can take a backup of the files as and when it is modified, u can append a timestamp to the backup file name this way u will know when the file was modified
0
 
LVL 18

Assisted Solution

by:armoghan
armoghan earned 124 total points
ID: 12122027
1.
If the lines are unique, you can put a check in database table of Unique rows only, and add all the rows in a batch only the new rows will be inserted and the rest will not

2.
The easiest approch would be, if you can.. Delete the file after reading the lines.

3.
Create a backup of the file and use some comparison API to compare the Files and get the changed lines only
http://www.araxis.com/merge/automation_ref.html
0
 
LVL 7

Assisted Solution

by:NipNFriar_Tuck
NipNFriar_Tuck earned 124 total points
ID: 12134188
How about getting the count of records in the DB (this would be the last line during the previous read) and looping until you get to the line after the count?  Then simply read the line and add to the db as your were doing...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question