Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am reading from Win32_NTLogEvent to read events from today with EventIdentifier 307 and 800 and save them in DB and this part is working fine but what i am trying to do is when the job is breaking down then i am getting the last record saved in DB and want to continue read the data which is bigger as last record which is in datatime but it doesnt work and its getting the whole data once again.

What I have tried:

queryString = $"SELECT * FROM Win32_NTLogEvent where logfile = 'Microsoft-Windows-PrintService/Operational' and TimeWritten > '{date}' and EventIdentifier = 307 or EventIdentifier = 800";

where: date is the last TimeWritten in DB

want: to continue read greater than last TimeWritten in DB
Updated 6-Nov-21 1:45am

1 solution

I'm assuming that the date/time of the log entry is being written to the database, and I also assume that you only want the last record added to the table, so try this:

FROM Win32_NTLogEvent 
WHERE logfile = 'Microsoft-Windows-PrintService/Operational' 
AND EventIdentifier IN (307,800)
ORDER BY datetimefield DESC;

Finally, in the code snippet I provided, I use datetimefield because I don't know what the name of your column is.

BTW, your logic is kinda screwed up (or you're just not expressing yourself very well). You can't retrieve data newer than the last data written to the db because it's never going to be there.
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