Re: ADO - Retrieve and update values
- From: "Vitali Kalinin" <vitkalinin@xxxxxxxxx>
- Date: Thu, 29 Sep 2005 15:03:22 +0300
> On occasions (it appears to be random) the above code doesn't work and the
> 'except' block is executed but one of the queries appears to lock and
> remains 'locked' no matter how often you retry. The application has to be
> closed before the code works again.
>
> I'm fairly new to this stuff but could anyone see why the above would
> occasionally lock or suggest a better way of retrieving a value and then
> updating it (for a variety of reasons, I can't use an autoinc \ identity
> number type).
>
> Many thanks
>
> Ian
AFAIK locking could occur if you are executing this procedure within
transaction (but you don't show us code which is dealing with them).
Select exposes shared lock on this record, which mean that record will be
available for reading from other connections, but they won't be able to
update it. Update exposes exclusive lock, which mean that this record won't
be available for read and update for others connections. Lock are closed
when transaction commits or rollbacks.
So my advices are as follows:
1.. Consider to switch to autoinc PK since you are just simulating its
functionality and this simulation is rather bad. Another option would be to
use GUIDs as primary key this way you could generate new ids on a client
without bothering server
2.. If (1) is not an option then you could do the following:
1.. Put all this stuff with select and update in the separate stored
proc with proper transaction handling, so that you could obtain new value in
a single shoot on the client side
2.. Add separate connection for ids generation so that to lock current
id record for the minimal time.
3.. Make sure that you are always Commiting or Rollbacking transactions
and keep them as short as possible
Regards,
Vitali
.
- References:
- ADO - Retrieve and update values
- From: IanJ
- ADO - Retrieve and update values
- Prev by Date: Re: ADO - Retrieve and update values
- Next by Date: Re: ADO - Retrieve and update values
- Previous by thread: Re: ADO - Retrieve and update values
- Next by thread: Re: ADO - Retrieve and update values
- Index(es):
Relevant Pages
|