In my application, one user at a time is supposed to work with an Access DB file for the entire "session" (time span he has the application open). The file shall be locked while one user is working with it.
I do so by using lock according to: How to lock a file with C#?
FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.None);
However when accessing the file via code, an exception is thrown, e.g.:
// Connection points to file locked before
using (OleDbConnection connection = new OleDbConnection(Connection)) {
connection.Open();
//...
System.Data.OleDb.OleDbException File is already being used
How to access previously locked file? Do I always have to remove the lock before accessing it? If so, how to ensure the file is not being accessed inbetween unlocking, accessing and relocking?