VB 2010 - lock/unlock DBF files via BDE


I use one older application, which was possibly created in Delphi and uses DBF files for storing data (DBase III and DBase IV). This application uses BDE v5.01 (Borland Database Engine) for access to DBF files.

I am creating VB.NET application and I need to write some records to these DBF files. This is not a problem for me, but there is the recommendation, that before writing is necessary to lock access for other users from Delphi application. This Delphi application uses BDE functions DbiAcqTableLock and DbiRelTableLock for these purposes.

My question is:

Is it possible in Visual Basic 2010 to lock and unlock DBF files (tables) similar like Delphi application does (via BDE, using functions DbiAcqTableLock and DbiRelTableLock)?

I would like to do it, because my application will work with DBF files at the same time with Delphi application.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
Use these functions i a way how other windows api functions in .net word (pinvoke):

UInt16 DbiRelTableLock(IntPtr, LongBool, DBILockType)

UInt16 DbiAcqTableLock(IntPtr, DBILockType)

Open in new window

skdanAuthor Commented:
Thank you for reply. I don't know exactly the values of parameters. Can I use for example this:



Open in new window

Sinisa VukSoftware architectCommented:
sorry, not in VB but shoud be understandable...
function SetTableLock(datasetHndl: THandle; bLock: Boolean): Integer;
    if bLock then
        Result := DbiAcqTableLock(datasetHndl, dbiWRITELOCK)  // lock
        Result := DbiRelTableLock(datasetHndl, True, dbiWRITELOCK); // release

Open in new window

values of DBILockType:
dbiNOLOCK = 0                            { No lock   (Default) }
dbiWRITELOCK = 1                       { Write lock }
dbiREADLOCK =2                         { Read lock }

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skdanAuthor Commented:
I have to study more things about it, but I believe, that your informations will help me to find solution. Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.