There is a client for communication and editing the database, how to find out if it is already open by another user on another computer? So far I have noticed that a temporary file is being created, .laccdb or .ldb for .accdb and .mdb, respectively, that is, you can check the existence of this file. But is there any other way? because these temporary files sometimes remain in the folder for a long time.
2 answers
The existence of the file can be checked with the help of the File.Exits function :
if (File.Exists("ΠΈΠΌΡ ΡΠ°ΠΉΠ»Π°")) { //..... } |
The second option:
OleDbConnection con; try { Console.WriteLine ("Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ΅ ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅"); con =new OleDbConnection("Provider=LCPI.IBProvider;"); Console.WriteLine("ΠΠΎΠΏΡΡΠΊΠ° ΠΎΡΠΊΡΡΡΠΎΠ΅ ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅"); con.Open(); Console.WriteLine("ΠΠ°ΠΊΡΡΡΡ ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅, Π΅ΡΠ»ΠΈ ΡΠΎΡΡΠΎΡΠ½ΠΈΠ΅ ΡΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ ΠΎΡΠΊΡΡΡ"); if (con.State == ConnectionState.Open) {con.Close();} } catch(OleDbException myOLEDBException) { Console.WriteLine("----------------------------------------"); for (int i = 0; i<=myOLEDBException.Errors.Count-1;i++) { Console.WriteLine("Π‘ΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠ΅ " + (i + 1) + ": " + myOLEDBException.Errors[i].Message); Console.WriteLine("Π»ΠΎΠΊΠ°Π»Π½ΠΈΠ΅: " + myOLEDBException.Errors[i].NativeError.ToString()); Console.WriteLine("Source: " + myOLEDBException.Errors[i].Source); Console.WriteLine("SQL: " + myOLEDBException.Errors[i].SQLState); Console.WriteLine("----------------------------------------"); } } |