【发布时间】:2020-03-11 21:33:54
【问题描述】:
我正在尝试使用 RStudio(32 位)中的“RODBC”包连接并读取数百个 MS Access 数据库文件。以前的程序用于打开和读取这些文件,并使用 system.mdw 系统数据库文件来指定用户权限,但我在 RODBC 文档中找不到任何描述如何在连接字符串中包含此文件的内容。这是我尝试过的,已经成功连接到数据库,但无法读取任何内容:
files <- dir("file directory to access files", recursive=TRUE, full.names=TRUE, pattern="\\.mdb$")
#2007 version is able to connect but can't read
dta <- odbcConnectAccess2007(files[1])
tables = sqlTables(dta)# can read all the table names in each file
habData = sqlFetch(dta, "Streams") #can't read the table content, see error message below
> habData
[1] "42000 -1907 [Microsoft][ODBC Microsoft Access Driver] Record(s) cannot be read; no read permission on 'Streams'."
[2] "[RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM \"Streams\"'"
#Older version is able to connect and still can't read
conn <- odbcConnect(paste("MS Access Database;DBQ=",files[4],sep = ""), uid = "Engine")
df <- sqlFetch(conn, "Streams") #can't read the table content, see error message below
我有 system.mdw 文件,但不知道如何将它与 Access 数据库相关联。有人在 R 中做过这个吗?也许用不同的包?
【问题讨论】: