[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dll CMO-Objekt with 2 clients

Posted on 2002-06-25
5
Medium Priority
?
189 Views
Last Modified: 2010-05-02
I have written a COM-dll in VB to write records in a
access database. This dll is used by 2 applications
simultaneous. Now I got the problem, that whenever both
applications want to write to the DB an error occurs.
I tried to lock the DB calling function as long as one
application writes to the DB, with a global variable like
this:
  Do While FunctionLocked = True
    Sleep (100)
  Loop
  FunctionLocked = True
  ProtocolWrite = AddProtRecord(ByVal ProtType, ByVal  IDType, ByVal InfoCount, vaInfo)
  FunctionLocked = False

  (In AddProtRecord are the database functions)



Does anyone know a solution for this problem. I know
I have to program a semaphore (maybe a C-programmer could help me) but I don not know how.

Some additional informations:
I connect the DB with:

cnDB.Provider = "Microsoft.Jet.OLEDB.4.0"
cnDB.Open PathDB
...

I open the recordset and write to the DB:
  With rsDB
    On Local Error GoTo CanNotOpenErr
    .CursorType = adOpenStatic
    .Open strName, cnDB, 3, 3
    If rsDB.RecordCount > 0 Then
      .MoveFirst
      .Fields(1).Value = Now
      .Fields(2).Value = ProtType
      .Fields(3).Value = IDType
      .Fields(4).Value = 88
      .Fields(5).Value = InfoCount
      .Fields(6).Value = ProtText
      .Update
    Else
      .AddNew
      .Fields(1).Value = Now
      .Fields(2).Value = ProtType
      .Fields(3).Value = IDType
      .Fields(4).Value = 88
      .Fields(5).Value = InfoCount
      .Fields(6).Value = ProtText
      .Update
    End If
   
    ' Recordset Connection schliesen
    .Close
  End With
...

Must I add additional information to the cnDB
(Connectionset Object) or the rsDB (Recordset Object)?


Greetings
   alpha
0
Comment
Question by:_alpha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 7107699
What are you using to update the database?  Have you tried letting the database manage the locking by setting pessimistic locking on the recordset object?  You can then check for errors from one user trying to update a locked record, etc.
0
 
LVL 3

Expert Comment

by:PNJ
ID: 7107753
You can't use a DLL to "share" variables. Each program gets a copy of the DLL in its own process space. So "FunctionLocked" is only ever "local" to each program. ie Two programs, two "FunctionLocked"'s

Sorry, can't help with the Access bits though. I'm fairly certain that it can be done. Anyone else know about record locking in Access between two or more programs?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7107820
Which error?

I hope that you are using INSERT SQL statement (instead of the AddNew method).
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7107824
There is a white paper here you can read to better understand the record locking techniques/performance of Microsoft Jet DB Engine:

"ACC: Microsoft Jet Utilities Available in Download Center (Q176670)"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q176670
0
 
LVL 18

Accepted Solution

by:
mdougan earned 1500 total points
ID: 7107850
You will have to be more specific about the contention.  Namely, how are you opening the Access database in the DLL?  Are you opening it Exclusively?  

Are you specifying a locktype?  Pessimistic, Optimistic?  

Are the two programs trying to update the same exact rows in the database table?  Or are they updating rows that might be physically near one another?

Are you using updatable recordsets or are you issuing Update SQL Statements?

For the greatest concurrency, you would normally open Read-Only recordsets, and then issue SQL Update statements to update the database.

If you want to be able to update the recordsets, then you should specify Optimistic Locking, and trap for errors relating to a record that has been updated by another program while the first program has been actively trying to update the row (you then have the option of letting the first program overlay the changes made by the other program or abandoning the changes).

With Pessimistic locking, Access will not only lock the particular record that you are editing, but also all other rows that exist on the same data page.  This might include several records if your row length is small.  For that reason, it is not advisable except in very specific circumstances.

You might want to tell us what data access methods you are using (ADO, DAO etc) and perhaps post a bit of code of how you open the database/connection and how you open the recordset and/or perform your updates.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question