Is manual locking necessary?

  • Thread starter Thread starter Yet
  • Start date Start date
Y

Yet

I have a window application with SQL 2005 database in a not bound to database
mode.
The application is to be in a multi-user environment.
How am I meant to maintain locking?
Should be considered:
1. the main form displays data from many tables
2. I don't want two users to open the same data for updates.
3. The form may be open for a long time (even hours)
4. The user should not loose any data entered and not yes saved ,because by
the time he comes to save it, the data was changed by somebody else.
 
Selects * some table (nolock) where
update sometable with (rowlock) where
--sql locks pages when rowlock is not used and if bussy server it could
cause deadlocks
--in most cases Rowlock is not needed, test with your conditions


delete sometable with (rowlock) where

Sql handles the locking in most cases just issue your
--- locking handeled by sql server
1. update
set col1='' where idkey=somekey

i have a busy site, so i use With (Rowlock) on my updates
2. Update with (rowlock)
set col1=''
where somekey =somevalue

3. begin transaction

update table1
if (@@error<>0 )goto problem
update table 2
if (@@Error<>0) goto problem
update table3
if (@@Error<>0) goto problem
goto success
Problem:
-- do somthing
rollback transaction
return 0
Success:
return 1

/commit transaction
 
if you really need NO Share thats pretty tough to do
selects can grab the data and a adapter can be set up to update it

i don't know a good way, except for setting a bit flag and a triger,
where u select and trigger checks to see if bit is 1, if so, raises a error
if set 0 returns the row or rows
you would have to test this with joins also make sure its working
need trigger on Select, and updates, not sure if u need them for deletes

play with them to meet your needs


DaveL
 
Back
Top