I am trying to understand how best to implement record locking on a program that may potentially be used by several people accessing a central database. I've spent a few hours reading around about record locking, so here is what I want to achieve and what I've implemented so far from what I've read:
The program will be to allow people to store, retrieve, edit and print quotations from a central database. The database might be either SQL Server 2000 or Access 2000. If a user opens a quotation I do not want any other user to be able to open it until the user currently in it closes it again.
To start with then I open a connection:
for Access, or for SQL Server I use
Then I want to open a quote, so I use
From what I have read I understand that by using a pessimistic lock, this will lock the record as soon as it "opened for editing" until it is updated. However I was confused over how to open for editing. DAO had an rs.edit, but ADO does not.
The only way I have found to do this is to open the recordset and then immediately change one of the columns, e.g. a last accessed date. This does have the desired effect in that if another user tries to open the same quote it gives an error which can be trapped, but I am wondering if this is the best way to go about it.
Could someone offer some advice please?
Many thanks
Stuart
The program will be to allow people to store, retrieve, edit and print quotations from a central database. The database might be either SQL Server 2000 or Access 2000. If a user opens a quotation I do not want any other user to be able to open it until the user currently in it closes it again.
To start with then I open a connection:
Code:
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbtest\data.mdb.mdb;Persist Security Info=False"
Code:
conn.open "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"
Then I want to open a quote, so I use
Code:
rs.open "SELECT qtHeader.orderno, qtHeader.customer, qtLines.PartNo
FROM qtHeader INNER JOIN qtLines ON qtHeader.orderno = qtLines.OrderNo
WHERE (((qtHeader.orderno)=123456));", conn, adOpenKeyset, adLockPessimistic
From what I have read I understand that by using a pessimistic lock, this will lock the record as soon as it "opened for editing" until it is updated. However I was confused over how to open for editing. DAO had an rs.edit, but ADO does not.
The only way I have found to do this is to open the recordset and then immediately change one of the columns, e.g. a last accessed date. This does have the desired effect in that if another user tries to open the same quote it gives an error which can be trapped, but I am wondering if this is the best way to go about it.
Could someone offer some advice please?
Many thanks
Stuart