# How is this possible?

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I need to scan an FTP for files,download any files which don't begin with "PROCESSED_", parse the file, and then put the data into a database, and then rename the file on the FTP as "PROCESSED_*", so that I don't process it again. Anyway, the code I wrote (C#) basically looks like this:
files = scan ftp

foreach (file in files)
{
if(file.StartsWith("PROCESSED_"))
continue

try
{
parse file
begin SQL transaction
put data in database
rename to "PROCESSED_*"
commit transaction
}
catch
{
rollback transaction
}
}

When I test it with just a few files or even do a few hundred and randomly check, everything seems fine... but when I let it run and do around 1-2k files, I catch one or two inconsistancies, e.g. a file is renamed as PROCESSED_ but the data isn't in the DB, or vice versa. The latter should not be possible because I don't commit the tranny untill after I rename the file... the former I think is possible but highly unlikely (and im not sure how to make it impossible...). I know this isn't exactly a question or bug you can just solve with all the vagueness, but I just dont understand how this is possible the way SQL transactions work.. I'm using C# w/ MSSQL. Thanks for any help.

##### Share on other sites
SQL Transactions won't protect the file rename operation, even if it's contained between the BeginTran and EndTran stuff.

Try rethrowing the error, or at least logging the error to a log or something. rather than just leaving it at "rollback tran"

##### Share on other sites
Why do you rename the file to something that you're searching for? You could end up inserting the same thing twice.

##### Share on other sites
hi !

a quick and maybe stupid question: why don't you check the DB if you already processed the file ??? having all files renamed doesn't look very nice to me. and using the DB for checking you are save to process very file just once.

cu

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013657
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!