问题
I have a .accdb Access DB file on a network drive that I have mapped to the Z:/ drive on my local machine. Can you connect ODBC to this?
This is the code to create the ODBC (usrAccessPath
is the string variable containing the file path):
connAccessDB <- odbcDriverConnect(paste0("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=",usrAccessDBPath))
This file path works:
C:/Users/boswelpa/Desktop/Projects/Absenteeism/Absenteeism Data.accdb
But this file path (mapped network drive) does not work:
Z:/SSG Reporting Team/For Thomas/Absenteeism Data.accdb
Same code, just different file paths.
回答1:
As commented, ODBC calls to MS Access databases such as R with RODBC accepts both local hard disk or network paths (i.e., Universal Naming Convention (UNC)), provided they follow the Windows file name rules. Of course, be sure to escape backslashes in R by doubling the character:
Hence, the following remote path should work:
accDB = "\\\\Path\\To\\Network\\Drive\\Access\\Database.accdb"
conn <- odbcDriverConnect(paste0("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=", accDB))
Also, a properly mapped local drive that maps to UNC should work:
accDB = "Z:\\Mapped\\Path\\To\\Network\\Drive\\Access\\Database.accdb"
conn <- odbcDriverConnect(paste0("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=", accDB))
来源:https://stackoverflow.com/questions/42515907/odbc-connect-from-r-to-access-db-accdb-file-on-network-drive