Circuits of blocking in Databases
At job with Databases in the multiuser mode there are situations when it is necessary to limit number of addressing users to the data. It is done{made} to prevent simultaneous updating the same recording, at global obnovlenim the data or at technical service of the Database.
The processor of Databases provides three levels of blocking:
* Blocking the Database. At this level of blocking to the Database one user can address only. Such level of blocking is applied to global change or updating of the data or at maintenance service of the Database - compression;
* Blocking the Table. At this level of blocking to the table one user can address only. Such level of blocking is applied when it is necessary to process at once some recordings of the table.
* Blocking page. At this level to the blocked page one user can address only. It is the lowermost level of blocking.
Blocking of the Database
Blokirivka at a level of the Database it is carried out by assignment to property exclusive, at opening a DB, value true. At use of an element of management by you data, in his{its} properties establish exclusive = true. If you use object dao at assignment of value to object db establish in true value of the second parameter of a method opendatabase:
set db = dbengine.opendatabase ("c:biblio.mdb", true)
When the Database is blocked thus, todrugie users cannot open her{it}. At attempt of the reference{manipulation} to the blocked Database you receive the message:
” could not use ' c:biblio.mdb '; file already in use. “
” It is impossible to use ' c:biblio.mdb '; the file is already used “
Simultaneously with it the mistake - 3045 is generated perekhvatyvaemaja, using which you can finish the program which addresses to the blocked Database since after occurrence of a mistake the program continues to be carried out though the Database and was not open.
At use of an element of management data in obrabotchik events error the following code is inserted:
private sub data1_error (dataerr as integer, response as integer)
if err = 3045 then
msgbox " Access to the Database is closed. Repeat search in some minutes. " And, vbcritical, "data_error"
end
end if
end sub
At use of object dao in that procedure where there will be a code of opening of the Database, it is inserted obrabotchik mistakes:
on error goto errhandler
' Here the code of opening of a DB and if there is a mistake - 3045 she is inserted
' It is intercepted and processed
errhandler:
if err = 3045 then
msgbox " Access to the Database is closed. Repeat search cherezneskol`ko minutes. " And _, vbcritical, "data_error"
end
end if

|