|
-
Jun 7th, 2000, 04:44 PM
#1
Thread Starter
Lively Member
We have made a simple application with a GUI, a business-object and a data-object, as an example how MTS works. When we start 3 applications (continuesly writing data into a database and retrieving a recordset with the complete database), we get deadlock errors in our data-object.
Is there a simple solution to avoid this problem? Maybe using another cursortype or cursorlocation will help? (we tested some possibilities, but nothing helped so far)
Ofcourse handling the error is a solution to this problem, but we would prefer not to cause the deadlock in the first place.
Any ideas or comments are welcome,
-
Jun 7th, 2000, 11:33 PM
#2
Addicted Member
Could it be an issue of open, unused recordsets?
-
Jun 8th, 2000, 02:19 PM
#3
Thread Starter
Lively Member
my function to add records to a database with an autonummer ID field
Hi Jason,
Thanks for your reply,
I checked your idea, but all recordsets are probably closed.
Our problem is locking the records by the recordset.Open command. We have reduced the problem by just selecting the first record.
What I try to make is an function to add records to a database with an autonummer ID field. The ID the database gives to the new record must be returned (this way the business-object knows where he can find the record he just saved).
I have added the code below, so you will see what I'm doing.
Public Function AddNew(iSampleType As Integer, sngQn As Single) As Long
Dim conSample As ADOdB.Connection
Dim rsSample As ADOdB.Recordset
Dim ObjContext As ObjectContext
Dim lngCountError As Long
Dim lngRecordSampleID As Long
Set conSample = New ADOdB.Connection
Set rsSample = New ADOdB.Recordset
Set ObjContext = GetObjectContext
lngCountError = 0
'Prepare connection
conSample.Provider = mPROVIDER
conSample.CONNECTIONSTRING = mCONNECTIONSTRING
conSample.Open
rsSample.CursorLocation = adUseClient
rsSample.Open "SELECT TOP 1 * FROM Samples", conSample, adOpenForwardOnly, adLockOptimistic, adCmdText
rsSample.AddNew
rsSample![sampletype] = iSampleType
rsSample![qn] = sngQn
rsSample.Update
lngRecordSampleID = rsSample![SampleID]
AddNew = lngRecordSampleID
rsSample.Close
ObjContext.SetComplete
SetToNothing:
Set rsSample = Nothing
Set conSample = Nothing
End Function
-
Jun 8th, 2000, 10:29 PM
#4
Guru
Why don't you do this?:
SELECT * FROM Samples where SampleID = -1
That way, no records will be returned, so no records will be locked. You'll still be able to add a new record.
In my apps that have this situation, I use a stored procedure and I retrieve the return value or use an output parameter for the identity field. No locking problems here.
HTH
Tom
-
Jun 12th, 2000, 01:34 PM
#5
Thread Starter
Lively Member
Thanks Tom, I will test your idea
Thanks Tom,
Because my database is pretty big (at this moment 300.000 records, just for testing), the WHERE statement could be slower.
I will test your idea, it will be a better solution than just trapping the deadlock error and trying again.
THANKS!
Fedor
-
Jun 13th, 2000, 02:35 PM
#6
Guru
Hi Fedor
if you use this SQL:
SELECT * FROM Samples where SampleID = -1
and the SampleID field is your primary key/autonumber or other indexed field, and there are no records that match that value, it should be a very quick lookup for your DBMS.
There should be no performance problems to worry about in this case
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
|