PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________

So here is an interesting puzzle�

I have an ASP page that increments a sequence number (by updating a value in a text file) and returns the result in a form field. The code works except for a major problem - the sequence number is being incremented twice. So I'm seeing a sequence number of 1,3, 5, etc.

What, if anything, are you doing to insure that TWO surfers hitting your page at exactly the same time don't both try to read the SAME number from the file, and then write the same number to the file, which will A) give two forms the same ID and B) probably completely trash the file.

This is known as a "race condition" and it's why you shouldn't be doing it this way. Tie your application to a database and use an SQL statement to increment a SEQUENCE. Or if your database is too broken to have sequences, create a silly little table with just an ID field and do an INSERT and then retrieve the ID from that insert.

Exactly HOW you retrieve that ID changes from database package to database package, but there is always a way to guarantee uniqueness and that you've got the right ID.

The database gurus spent a lot of time getting this right. Don't try to re-invent the wheel.

I can guarantee that unless you have a very special situation or some external business logic that forces only ONE surfer at a time to be getting an ID number that sooner or later you will get big if you keep your current plan.

The code is correct because if I remove the
Response.ContentType = "application/vnd.fdf"
then I can see the raw FDF and it increments correctly. So it somehow seems as if the ASP routine is being called twice if Acrobat is in the picture. FDF toolkit is not in the picture because I am generating my own FDF from scratch (and it is correct because the form, with the form field data, is being brought up).


What is even more interesting is that Mozilla 1.6 works correctly and the sequence number increments the way it should.

There is NOTHING you can do to stop Internet Exploder from accessing the same URL as many times as it feels the need to while fetching your document.

You could, perhaps, detect the user's browser, and if it was IE, send them a unique COOKIE along with their ID, and if they come back within X seconds just give them the same ID you just gave them, rather than a new one.

Or you could just now worry about it, and deal with the fact that some numbers will be skipped.

You probably have to do this anyway, as sooner or later some browser crash will cause an unused ID number.

The ASP page is being invoked by directly calling it directly (i.e. <http://localhost/TestSeqnum.asp>http://localhost/TestSeqnum.asp) in the html. Environment is Windows XP Pro SP1 and Acrobat 6.0.1.

--
Like Music?
http://l-i-e.com/artists.htm

To change your subscription:
http://www.pdfzone.com/discussions/lists-pdfforms.html



Reply via email to