Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
i have a receiver windows application which receives stream from a port (Logical port) on which my clients is sending me some feed.
my receiver receives the feed and write it in to a text file.

I have an other application which reads the text file parse it and dump it in to mysql database.

if for some reasons if i have to stop (close) my application which dumps data in to database and restart it. after restarting the application i want to read the text file where i left it while reading it before.
i mean to say that if i have read 100 lines from text file out of 1000 and for some reasons i have to close my application.
now i start my application again and want to start from 101 line.

bellow is the text file format

HTML
"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLD-OC12","","ORD","49433","50","49485","50","",""

"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLD-OC12","","ORD","49435","50","49485","50","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49403","5","49454","5","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49405","5","49454","5","",""

"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"

"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"

"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"

"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"
Posted
Updated 11-Aug-12 10:24am
v2

Hi,

We are not sure how your application is working, but making some assumption i am giving you one solution.

Assumptions
1) each text file have single log entry
2) you have single text file having all data.
Note : even other solutions are possible if above assumptions are incorrect.

Solution
- You can check your database table records and go directly on that line and start reading. Let me know if you have problem with reading text file from particular position.

ex : you have 100 records in your database then read your text file from 101 and your application will again dump data in database.

hope it works for you, Let me know if you have any query.

Thanks
-Amit Gajjar
 
Share this answer
 
Comments
Farhan Qureshi 16-Aug-12 3:42am    
yes i have single text file and at the day end the size of text file is around 250 to 350 mb

and please help me with example of reading text file from particular position
AmitGajjar 16-Aug-12 4:12am    
then proposed solution will work for you.
Farhan Qureshi 16-Aug-12 5:45am    
YES
but need example
reading text file from particular position.
AmitGajjar 16-Aug-12 6:47am    
http://stackoverflow.com/questions/1262965/c-how-do-i-read-a-specified-line-in-a-text-file
you mean to save last line no. some where and when application start retrieve that line no.,
read text file's lines on by one and nothing to do till counter reaches the line no. means if counter>= line_no then add entries in database

you can store Line-no three ways.
1. In database
2. In global application user-defined property (settings.designer.vb page)
3. In Registry key.

do not forget to increase line-no and update it's status in (database or global application user-defined property or registry key - any of source you used) when you have processed the line.

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900