How to determine whether to open the current database in exclusive way?

zhaozj2021-02-16  49

How to determine whether to open the current database in exclusive way?

problem:

How to determine whether to open the current database in exclusive way? When the link or other database is operated with ADO, if the database is operated in an exclusive way, it will be wrong, how to determine whether the database is already exclusive?

method one:

Very simple, just determine if the following letterproject.connection.connectionstring contains the following letters Jet OLEDB: Database Locking Mode = 0 to write a function:

Function TestlockMode () IF INSTR (CurrentProject.Connection.connectionstring, "Jet OLEDB: Database Locking Mode = 0")> 0 THEN MSGBOX "This database has already opened" Else Msgbox "in exclusive ways This database does not use exclusive way" end iFend Function The following is the result of debug.print currentproject.connection.connectionstring for reference: provider = microsoft.jet.OLEDB.4.0; user ID = admin; data source = l: / ibm winxp / desktop / mdb / Record. Mdb; mode = Share Deny Read | Share Deny Write; Extended Properties = ""; Jet OLEDB: System database = C: / Documents and Settings / ec / Application Data / Microsoft / Access / System.mdw; Jet OLEDB: Registry Path = SOFTWARE / Microsoft /Office/10.0/access/jet/4.0; jet = ""; Jet OLEDB: Engine Type = 5; Jet OLEDB: Database Locking Mode = 0; Jet OLEDB: Global Partial Bulk OPS = 2; Jet OLEDB: Global Bulk Transactions = 1; Jet OLEDB: New Database Password = ""; Jet OLEDB: Create System Database = False; Jet OLEDB: Encrypt Database = False; Jet OLEDB: Do not Copy Locale on Compact = False; Jet OLEDB: Compact WITHOUT replica repair = false; Jet OLEDB: SFP = FALSE

Method Two:

Very simple, you only need to turn on the database in the program to open the database, if you return the error number, you can judge. Just like many of the problems in this site, it can be judged by the wrong trap.

Function TestlockMode () ON ERROR RESUME NEXT DIM CONN AS New AdoDb.connection Conn "provider = microsoft.jet.Oledb.4.0; user ID = admin; data source = l: / IBM Winxp / Desktop / MDB / Record. MDB; Jet OLEDB: Database Locking Mode = 0; "If Err.Number = -2147467259 THEN MSGBOX" file is already in use, is estimated to be opened by others "end ifnd function method three:

Of course, you can also read the currentdb attribute directly to determine if it is already exclusive.

http://www.access911.net webmaster collection

转载请注明原文地址:https://www.9cbs.com/read-24515.html

New Post(0)