Discussion Locked

ASP: Dealing with simultaneous access?

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

I'm writting an ASP application where users complete an HTML form (survey) and when they submit the form, I must create a folder on the server containing the form's data in a XML file. This folder's name is comprised of the current date and a incremented number (ex. 25012002-001). My concern is about how to effectively deal with simultaneous users submitting the form. If two or more users hit the "submit" button and launch the code to create the next available folder at the same time,how can I ensure that the folders will be created appropriately for each user?

Is there a way to "Lock" each session when a user starts the application? Locking the application?

I'd appreciate any help!

Thanks!

3 replies

by chris.lewis

How about Application.Lock?

From the SDK...

Lock
The Lock method blocks other clients from modifying the variables stored in the Application object, ensuring that only one client at a time can alter or access the Application variables. If youdo not call the Unlock method explicitly, the server unlocks the locked Application object when the .asp file ends or times out.

Syntax

Application.Lock

Example

<%
Application.Lock
Application("NumVisits") = Application("NumVisits")+ 1
Application("datLastVisited") = Now()
Application.Unlock
%>

This application page has been visited
<%= Application("NumVisits") %> times!

In the preceding example the Lock method prevents more than one client from accessing thevariable NumVisits at a time. If the application had not been locked, two clients could try to increment the variable NumVisits simultaneously.

So in your submit.asp, when you create a new folder, do something like this:

'Start of new folder
application.lock
iFolder = GetNextFolderName()
objfso.CreateFolder(ifolder & "-" & YEAR(now) & "-" & Month(now))
Application.unlock.

'GetNextFolderName should use your current numbering schema
'By locking, incrementing, creating, & unlocking,
'you've eliminited the multi-submit issue.

This discussion is closed to new replies.