MDB opened indication
-
hi, i use VB.NET to develop an application which uses local MDB files as databases, my question is: is there anyway that i can indicate if a certain mdb file is already opened by another user ( even in access client ). the goal is if for example a user open 2 instances of my application and connect with both instances to the same mdb file, i would like to display a warning messege on the 2nd connection that there is already 1 connection opened to this particular mdb file. thanks in advance!
Net
-
hi, i use VB.NET to develop an application which uses local MDB files as databases, my question is: is there anyway that i can indicate if a certain mdb file is already opened by another user ( even in access client ). the goal is if for example a user open 2 instances of my application and connect with both instances to the same mdb file, i would like to display a warning messege on the 2nd connection that there is already 1 connection opened to this particular mdb file. thanks in advance!
Net
What I have done in the past, under a similar Access MDB requirement, is try to open the database exclusively, while trapping for the error if another user already has it opened, and then display the warning message if the error occurs. If the 'already opened' error did not occur, I would simply close the connection and then re-open the MDB shared.
-
hi, i use VB.NET to develop an application which uses local MDB files as databases, my question is: is there anyway that i can indicate if a certain mdb file is already opened by another user ( even in access client ). the goal is if for example a user open 2 instances of my application and connect with both instances to the same mdb file, i would like to display a warning messege on the 2nd connection that there is already 1 connection opened to this particular mdb file. thanks in advance!
Net
Well you can improvise. Every time you check if some text file exists in the same directory as your databse. If it does not exists you create it. If it does exists that means that someone already opened the connection and you can implement code that generates warning. Just don't forget to delete this file when you close connection. As for the access client, every time you open mdb file with access or any other database managing software (this includes your connection that you create from your application) another file will be created in the same folder as your database. It will have the same name but different extension (.ldb). So you can combine this feature also with the one i described to get more detailed informatiopn. I will try to code one example here(let us say your database name is "base.mdb"):
connection.Open();
if(File.Exists("C:\\opened.txt") == true && File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by your application");
if(File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by Access client");
Else
File.CreateText("C:\\opened.txt")Of course dont forget to delete the text file after closing connection:
connection.Close();
if(File.Exists("C:\\opened.txt") == true)
File.Delete("C:\\opened.txt")Any way this is the general idea. In a text file you could write much additional information on who opened the databse, when, etc.. Cheers!
-
Well you can improvise. Every time you check if some text file exists in the same directory as your databse. If it does not exists you create it. If it does exists that means that someone already opened the connection and you can implement code that generates warning. Just don't forget to delete this file when you close connection. As for the access client, every time you open mdb file with access or any other database managing software (this includes your connection that you create from your application) another file will be created in the same folder as your database. It will have the same name but different extension (.ldb). So you can combine this feature also with the one i described to get more detailed informatiopn. I will try to code one example here(let us say your database name is "base.mdb"):
connection.Open();
if(File.Exists("C:\\opened.txt") == true && File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by your application");
if(File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by Access client");
Else
File.CreateText("C:\\opened.txt")Of course dont forget to delete the text file after closing connection:
connection.Close();
if(File.Exists("C:\\opened.txt") == true)
File.Delete("C:\\opened.txt")Any way this is the general idea. In a text file you could write much additional information on who opened the databse, when, etc.. Cheers!
-
Well you can improvise. Every time you check if some text file exists in the same directory as your databse. If it does not exists you create it. If it does exists that means that someone already opened the connection and you can implement code that generates warning. Just don't forget to delete this file when you close connection. As for the access client, every time you open mdb file with access or any other database managing software (this includes your connection that you create from your application) another file will be created in the same folder as your database. It will have the same name but different extension (.ldb). So you can combine this feature also with the one i described to get more detailed informatiopn. I will try to code one example here(let us say your database name is "base.mdb"):
connection.Open();
if(File.Exists("C:\\opened.txt") == true && File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by your application");
if(File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by Access client");
Else
File.CreateText("C:\\opened.txt")Of course dont forget to delete the text file after closing connection:
connection.Close();
if(File.Exists("C:\\opened.txt") == true)
File.Delete("C:\\opened.txt")Any way this is the general idea. In a text file you could write much additional information on who opened the databse, when, etc.. Cheers!
First, this is a race condition waiting to happen. Second, applications don't always end cleanly. Sooner or later something will go wrong and you will end up with the "opened.txt" file existing even though no one has the database open, or the .ldb file can hang around if Access does not close cleanly.
-
Well you can improvise. Every time you check if some text file exists in the same directory as your databse. If it does not exists you create it. If it does exists that means that someone already opened the connection and you can implement code that generates warning. Just don't forget to delete this file when you close connection. As for the access client, every time you open mdb file with access or any other database managing software (this includes your connection that you create from your application) another file will be created in the same folder as your database. It will have the same name but different extension (.ldb). So you can combine this feature also with the one i described to get more detailed informatiopn. I will try to code one example here(let us say your database name is "base.mdb"):
connection.Open();
if(File.Exists("C:\\opened.txt") == true && File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by your application");
if(File.Exists("base.ldb") == true)
MessageBox.Show("Connection is opened by Access client");
Else
File.CreateText("C:\\opened.txt")Of course dont forget to delete the text file after closing connection:
connection.Close();
if(File.Exists("C:\\opened.txt") == true)
File.Delete("C:\\opened.txt")Any way this is the general idea. In a text file you could write much additional information on who opened the databse, when, etc.. Cheers!
You don't need to create a text file. Access creates a .ldb file to hold locking information when the .mdb is opened. Just look for that. :) There are some circumstances when Access does not create the .ldb file e.g. the directory that the .mdb is in is set to read only. But then Access will only allow one user to open the database so the second attempt will generate an error or exception.
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis