Solved

StreamReader reading appended lines

Posted on 2004-09-22
7
281 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
7 Comments
 
LVL 4

Accepted Solution

by:
somnatic earned 32 total points
Comment Utility
* 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now