Skip to content

Test if the database can be written to, early in the script #1

@raniets

Description

@raniets

When writing a table to the Access-file, I expect that I will need Exclusive access to the file. If that is the case, the script should test if I do have exclusive access before starting the data crunching.
One solution is to open the file connection with exclusive access. This will (hopefully) fail when someone has the file open.
Using DBI, this seemed to work (but is not implemented in the RMD file):

Connection string must contain "Exclusive=1;"
Code:
dbdriver <- "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Exclusive=1;DBQ="
dbname <- paste(DBroot, KH_db, sep = "/") # Har satt opp parameterne i første chunk.
dbconn <- DBI::dbConnect(odbc::odbc(),
.connection_string = paste0(dbdriver, dbname),
encoding = "latin1")

This opened the connection when the Access file was closed, but failed when the file was open in an Access window. "The file is already in use".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions