ODBC connect from R to Access DB .accdb file on Network Drive

亡梦爱人 提交于 2019-12-11 04:44:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!