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.

  • one
    The presence of the lock file does not mean anything. Try to connect to the database in monopoly mode - if it is already used by someone, it will not work ... - Akina

2 answers 2

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("----------------------------------------"); } }