How to lock DB files with C # so that third-party programs cannot access them

My requirement is "Blocking our database files is performed in such a way that all actions taken as part of our application process are allowed, only the access of third-party applications / services is blocked." To ensure that third-party software does not block any of our database files after starting our application, we must explicitly lock all database files to prevent this.

Background: I am working on a desktop application and sql ce as a database and N-hibernate. Several times, when our application launches third-party programs, such as backup software, which will run frequently and back up the system at this time, it blocks our db files.

so my requirement is that when I launch my application, I have to lock my db files so that any thread or any action with my application should perform all operations on the database, but third-party operations should be limited.

I tried with the FileLock sample, but this does not work in my application when you perform some db operation via N-hibernated. Please help me with this, it is really great, if so, please let me know.

+7
source share
3 answers

Using File.Open for write operations without disposal, a file lock is usually saved. Others will not be able to write, but they can still read it.

0
source

Create a new account / user. Overwrite the file permission only to this user. and personalize your application for this newly created user. as a result, another user cannot use your file.

0
source

I do not know since SQLCE began supporting a desktop application. I prefer to use SQLite . It supports locking a database file using only the sqlite statement. Check this. Please let me know if you need more information.

-one
source

All Articles