ASPRunnerPro 5.2
This schema requires two additional fields in the database table to implement record locking.
IsLocked - Yes/No field, LockTime - Datetime field.
Timeout is set to 20 minutes. More sophisticated version can also save user name who locked the record and display it on the page.
Sub EditOnLoad()
set rstmp = Server.CreateObject("ADODB.Recordset")
rstmp.Open "select IsLocked, LockTime from " & strTableName & " where " & where, dbConnection
if rs("IsLocked")=1 and DateDiff( "n", rs("LockTime"), now() )<20 then
Response.write "Record is locked. Come back later"
rstmp.close : set rstmp = nothing
Response.end
else
rstmp.close : set rstmp = nothing
dbConnection.Execute "update " & strTableName & " set IsLocked=1, LockTime=now() where " & where
end if
End Sub
To unlock the record we can use BeforeEdit event:
Function BeforeEdit(dict, where)
dbConnection.Execute "update " & strTableName & " set IsLocked=0, LockTime=now() where " & where
End Function
ASPRunnerPro 5.0
Use custom event (Insert ASP code snippet option on the Visual Editor tab) instead of EditOnLoad event. Replace wherevariable with strWhereClause in this event:
set rstmp = Server.CreateObject("ADODB.Recordset")
rstmp.Open "select IsLocked, LockTime from " & strTableName & " where " &
strWhereClause, dbConnection
if rs("IsLocked")=1 and DateDiff( "n", rs("LockTime"), now() )<20 then
Response.write "Record is locked. Come back later"
rstmp.close : set rstmp = nothing
Response.end
else
rstmp.close : set rstmp = nothing
dbConnection.Execute "update " & strTableName & " set IsLocked=1, LockTime=now() where " &
strWhereClauseend if