This topic is locked

Preventing two peolpe from editing the same record at once.

5/29/2007 9:33:30 AM
ASPRunnerPro General questions
S
swiersman author

Hi All:
I have a problem that when two people are editing the same file at the same time, the last perosn who submits thier changes overwrites the other person's changes. Is there a way that I can have only one person allowed to work with a record at a time?
Thanks for any help.

pplaut 5/29/2007

My guess is your record locking is not setup correctly.

Peer

Sergey Kornilov admin 5/30/2007

You need to implement record locking using events.

Add an additional field to this table named IsLocked.

I.e. you can lock the record in EditOnLoad event and unlock it in AfterEdit event.

If record is locked already EditOnLoad event should display a message.
Bear in mind that some people can close browser after proceeding to the edit page and records stays locked.

I would suggest to use lock expiration in this case (say if record is locked for 20 minutes we believe user closed the browser and lock can be removed). Also you need to provide admin with an option to unlock any/all records manually.

S
swiersman author 6/22/2007

You mention accomplishing through record locking on Events.
I have made another column in the DB called "IsLocked" and set it's default value to "false".

Could you assist me in providing what the the Event OnLoad code should look like to change this to "true".

I beleive I would also need some sort of check during the Eveny OnLoad to see if the "isLocked" value is already set to "true" and redirect them to a message page.
Any assitance yu could provdie would help tremendously since ths is causing quite a problem...

Sergey Kornilov admin 6/26/2007

Here is the sample code.
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
S
swiersman author 7/5/2007

Here is the sample code.

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
S
swiersman author 7/5/2007


[color=#FF0000]Then I rebuilt ASP project picking up two new columns in my query, hiding them in the form and adding the code you provided in the events window.
<%
Sub AfterAdd()

'** Redirect to another page ****

Response.Redirect "Results_list.asp"
End Sub
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
Sub AfterEdit()

'** Redirect to another page ****

Response.Redirect "../MessageBoxes/TRCReviewComplete.htm"
End Sub
%>
[color=#FF0000]I know get this error when I click the edit button for any record from the LIST.asp page:
ASP error happened
Technical information

Error number 450

Error description Wrong number of arguments or invalid property assignment

URL /FormsV2_1/TRCMember/TEST_TRCApprovalConsole/Results_edit.asp

SQL query select [ID], [GENERAL_INFORMATION], [Requester], [PMOwner], [MODReleaseDate], [MODReleaseTime], [ProductionReleaseDate], [ProductionReleaseTime], [CHARGED_TO], [ChargedTo], [ProjectWorkOrderName], [WONumber], [WOChargeType], [TYPE_RELEASE], [SelectSoftware], [SoftwareSub], [SelectInfrastructure], [InfrastructureSub], [COMPANIES_AFFECTED], [CompanyAffectedBunkerHill], [CompanyAffectedMWAC], [CompanyAffectedPILG], [PILGSub], [CompanyAffectedPRAC], [PRACSub], [CompanyAffectedPAL], [PALSub], [CompanyAffectedHP], [HPSub], [INFORMATION], [ChangesToBeMade], [SpecialInstructions], [MOD_CHECKLIST], [MODQ1Status], [Q1TechLeadApproval], [MODQ2Status], [Q2DBAAproval], [MODQ3Status], [Q3DBAApproval], [MODQ4Status], [MODQ5Status], [MODQ6Status], [Q6CommunicatedBy], [MODQ7Status], [MODQ8Status], [Q8VSSLabel], [MODQ9Status], [Q9CVSLabel], [MODQ10Status], [Q10EARLabel], [MODQ11Status], [ResourceID], [MODQ12Status], [PRODUCTION_CHECKLIST], [ChecklistItemTested], [ChecklistTechReview], [ProdTechReviewer], [ChecklistPostTesting], [ChecklistOperationalDocumentation], [ChecklistHelpDeskDocumentation], [ChecklistDevelopmentReleaseTeam], [Checklist5DayCommunication], [ChecklistBackoutRecovery], [ChecklistPrerequisites], [ChecklistSecurityIssues], [ChecklistSignOff], [ProdPMSign], [SignOff_Captured], [ProdVSSLabel], [txtProdVSSLabel], [ProdCVSLabel], [txtProdCVSLabel], [ProdEARLabel], [txtProdEARLabel], [WhoWillPreform], [OtherReleasor], [SOFTWARE_RELEASE], [CommonCode], [CodeBeingMoved], [How], [From], [To], [ApplicationBackOutProcess], [INFRASTRUCTURE_RELEASE], [ServerNames], [NetworkDeviceNames], [HardwareChanges], [DatabaseChanges], [OSSWFirmwareLevelChange], [ApplicationServicesAffected], [InfrastructureBackOutProcess], [BUSINESS_REQUIRMENTS], [ApplicationServiceLevel], [SystemRecovery], [BackUpRequirements], [RetentionPeriod], [SecurityConsiderations], [ATTACHMENTS], [Attachment], [ChecklistDesktopImpact], [txtStatus], [EMERGENCY_RELEASE], [EmergencyRootCause], [EmergencyPrevention], [EmergencyImpact], [APPROVALS_AND_STATUS_HISTORY], [TrueModDate], [TrueModReleaser], [TrueProdDate], [TrueProdReleaser], [TRC APPROVALS], [TRC_IF], [TRC_IF_Approvers], [TRC_IF_Approval], [TRC_IF-Comments], [TRC_AD_NE], [TRC_AD_NE_Approvers], [TRC_AD_NE_Approval], [TRC_AD_NE_Comments], [TRC_AD_NJ], [TRC_AD_NJ_Approvers], [TRC_AD_NJ_Approval], [TRC_AD_NJ_Comments], [TRC_DATA], [TRC_DATA_Approvers], [TRC_DATA_Approval], [TRC_DATA_Comments], [TRC_PUBLISHING], [TRC_Publishing_Approvers], [TRC_Publishing_Approval], [TRC_Publishing_Comments], [TRC_NETWORK], [TRC_Network_Approvers], [TRC_Network_Approval], [TRC_Network_Comments], [TRCNetworkResource], [TRC_WEBSERVICES], [TRC_Webservices_Approvers], [TRC_Webservices_Approval], [TRC_Webservices_Comments], [TRCWebservicesResource], [TRC_DATABASING], [TRC_Databasing_Approvers], [TRC_Databasing_Approval], [TRC_Databasing_Comments], [TRC_PRODSERVICES], [TRC_ProdService_Approvers], [TRC_ProdService_Approval], [TRC_ProdService_Comments], [ECCApproval], [EMERGENCY_CHANGE_APPROVALS], [ECPetruff], [ECPetruffComments], [ECWilson], [ECWilsonComments], [ECVerrier], [ECVerrierComments], [ECSmith], [ECSmithComments], [ECCasagrande], [ECCasagrandeComments], [ECReleaseDate], [ECCECAppSysEffected], [TrueModTime], [TrueProdTime], [ContactNumber], [DBAPassword], [ReleaserNotes], [Attachment2], [Attachment3], [Attachment4], [FirewallRequiredSelect], [FirewalDefinition], [TRC_SQLDBA], [TRC_SQLDBA_Approvers], [TRC_SQLDBA_Approval], [TRC_SQLDBA_Comments], [TRCSQLResource], [TRC_DB2DBA], [TRC_DB2DBA_Approvers], [TRC_DB2DBA_Approval], [TRC_DB2DBA_Comments], [TRCDB2Resource], [TRC_WINDOWSADMIN], [TRC_WindowsAdmin_Approvers], [TRC_WindowsAdmin_Approval], [TRC_WindowsAdmin_Comments], [TRCWindowsAdminResource], [TRC_WASADMIN], [TRC_WAS_Approvers], [TRC_WAS_Approval], [TRC_WAS_Comments], [TRCWASResource], [TRC_STORAGE], [TRC_Storage_Approvers], [TRC_Storage_Approval], [TRC_Storage_Comments], [TRCStorageResource], [AssignedResource], [TRC_AI], [TRC_AI_Approvers], [TRC_AI_Approval], [TRC_AI_Comments], [Impact], [Test_Section], [Test_Level_Applied], [Test_Documentation], [Test_Complete], [IsLocked], [LockTime] From [X_ReleaseRequest].[Results] WHERE ([txtStatus] in ('Ready for TRC Review','Ready for TRC review')) and ([Results].[ID]=2477)

Additional info Event: Call EditOnLoad(sWhere)
Any help would be great!!

Sergey Kornilov admin 7/5/2007

What version of ASPunnerPro you use?
PS. There is one more thing missing - you need to unlock the record in BeforeEdit event.

This is just a sample code that gives you the idea. If you decide to use it you need to troubleshoot it on your own.