Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lock a record or a table?
Message
 
 
To
14/07/2016 11:47:29
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01638381
Message ID:
01638390
Views:
46
>>Hi,
>>
>>Do you know of a method to lock a row or a small table in SQL Server from VFP application? Such that if the connection handle is lost, after a while, the SQL Server releases the lock?
>>
>>TIA
>
>I don't know the full specs of your requirements, but imagining that you just want to make sure that a connection / workstation grabs the exclusive right to a state until it releases it back for all connections / workstations or a timeout expires, in a way that can be operated from VFP, perhaps this code could be of help. It uses a table with a single row (did I understand your idea correctly?).
>
>For a Lock, run the LockSQL statements: if the returned (single) row contents is equal to the caller workstation id, then the lock is yours; if not, someone else has the lock. For an Unlock, run the UnLockSQL statements.
>
>
>LOCAL WorkStation AS String
>LOCAL LockSQL AS String
>LOCAL UnLockSQL AS String
>LOCAL LockTimeout AS Integer
>
>* locker table
>* :structure
>* lockerId varchar(200)
>* lockerTime datetime
>* 
>* :initial contents (1 row)
>* NULL, NULL
>
>m.WorkStation = SYS(0)
>m.LockTimeout = 20		&& in seconds
>
>TEXT TO m.LockSQL NOSHOW FLAGS 1
>
>BEGIN TRANSACTION;
>UPDATE locker
>	SET lockerId = ?m.WorkStation, lockerTime = GETDATE()
>	WHERE lockerId IS NULL OR lockerId = m.WorkStation OR DATEDIFF(second, lockerTime, GETDATE()) >= ?m.LockTimeout;
>COMMIT;
>
>SELECT lockerID FROM locker;
>
>ENDTEXT
>
>TEXT TO m.UnLockSQL NOSHOW FLAGS 1
>
>BEGIN TRANSACTION;
>UPDATE locker
>	SET lockerId = NULL
>	WHERE lockerId = ?m.WorkStation;
>COMMIT;
>
>ENDTEXT
>
Thank you, Antonio. I have not even thought about locking a record in a VFP table. Which may work. I will try your code.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform