How to 'lock' a file?

  • Thread starter Thread starter nvx
  • Start date Start date
N

nvx

Hi,
I have an application working with an Access database and I need to
'lock' the currently opened DB file in order to prevent it to be
deleted, modified by other applications etc. Does anyone know how to
achieve this? An information regarding unlocking a file would also be
appreciated.

Thanks for any help...

Regards
nvx
 
Hi,
I have an application working with an Access database and I need to
'lock' the currently opened DB file in order to prevent it to be
deleted, modified by other applications etc. Does anyone know how to
achieve this? An information regarding unlocking a file would also be
appreciated.

Usually, methods that allow you to open a file provide you with the option
of passing a FileShare argument letting you specify whether or not you want
to allow other processes to have read or write access to your file while
you have it open. Have a look at the doc for FileShare. The File.Open()
method for example accept a FileShare argument. If you choose not to let
other processes have access to your file while you are having it open, you
can remove this "lock" simply by closing the file.

I'm not sure what happens in the particular case of an Access file. I seem
to remember from the time we were using Access for our database that you
can specify in the connection string what type of file sharing you want.
 
Thank you very much for your time. I briefly checked the DB file
properties in my VC# Express Edition and found nothing similar. It is
probably caused by the version of VS, but I'm not sure. I'll try to
google this 'FileShare' thing to find out more...

Regards
nvx


Mehdi napsal:
 
Thank you very much... :) That seems to be the exact thing I need... I
really appreciate your effort. Since I'm a newbie I don't know the
proper keywords to search for.

Regards
nvx


MarkTheNuke napsal:
 
Thank you very much... :) That seems to be the exact thing I need... I
really appreciate your effort. Since I'm a newbie I don't know the
proper keywords to search for.

Regards
nvx


MarkTheNuke napsal:
 
Thank you very much... :) That seems to be the exact thing I need... I
really appreciate your effort. Since I'm a newbie I don't know the
proper keywords to search for.

Regards
nvx


MarkTheNuke napsal:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top