|
-
Jul 1st, 2002, 03:39 PM
#1
Thread Starter
New Member
Locking a table
How can I lock a table to insert x records with .addnew so no one else will be able to add a record durring this process. I need to have continous record (ID) numbers? VB 6 - ADO 2.7 - Using Jet or SQL Server (depending on the user setup)
Thanks
-
Jul 1st, 2002, 11:53 PM
#2
Frenzied Member
Table locking isn't really used anymore. I know that as of SQL Server 6.5 and later it isn't supported, and MS Access doesn't supported it either (I could be wrong). I'm not sure why you would need to lock the table anyway, since standard locking (Record Level) just prevents users from accessing records which are already being viewed by another user. My guess would be that you shouldn't need to lock anything, since the records you are adding won't be viewed by another user, since they won't exist prior to you inserting them.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 2nd, 2002, 07:32 AM
#3
Thread Starter
New Member
Maybe I'm confused. But couldn't another user do an .addnew in the middle of my .addnew - causing my records to be non sequential?
Thanks
-
Jul 2nd, 2002, 10:24 AM
#4
Addicted Member
If you want to truly lock the table so that it can't be used, then rename it, add your records, then name it back.
You should find that an append query is fast enough to add the records that you want before anyone else can interfere with the sequence.
-
Oct 23rd, 2002, 02:20 PM
#5
Let me in ..
R u okay ?
Renaming the table might cause serious problems in other programs and the users using the table. It won;t just ignore this thing but will raise serious errors.
-
Oct 24th, 2002, 03:04 AM
#6
Addicted Member
Yes - I'm fine, thank-you.
How can I lock a table to insert x records with .addnew so no one else will be able to add a record durring this process.
So, hmmm ... let me think - what better way to lock a table than to remove it from the attachments of other programs?
All you do thereafter is ... put it back!.
-
Oct 24th, 2002, 04:14 AM
#7
SQL Server supports table level locks. If you wish to implement a table level lock
You could do the following.
1) Use "HOLDLOCK" when you select from a table.
Like for instance -
"Select * From Employees (TABLOCK HOLDLOCK)" when you open a recordset.
Use this in a transaction. Other users should not be able to enter records in the database.
this is what I did to keep the table locked until the update had been done.
Code:
Dim adoCn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
strSQL = "Select * From Employees (TABLOCK HOLDLOCK)"
adoCn.Open "Provider=SQLOleDB.1;Initial Catalog=Northwind;DataSource=ZEUS;User ID=sa;"
adoCn.BeginTrans
rs.Open strSQL, adoCn, adOpenKeyset, adLockPessimistic
Do While Not rs.EOF
Debug.Print rs.Fields(0)
rs.MoveNext
Loop
rs.Close
adoCn.CommitTrans
Cheers!
Abhijit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|