Solved

Dll CMO-Objekt with 2 clients

Posted on 2002-06-25
5
187 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 500 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

724 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