Solved

StreamReader reading appended lines

Posted on 2004-09-22
7
286 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 32 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 31 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 31 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 31 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

751 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