Connecting 32-bit R to a 32-bit Access database

丶灬走出姿态 提交于 2019-12-24 02:05:17

问题


I am using 32-bit R with RStudio to try and connect to an .accdb file. I have 32-bit MS Access running on my machine.

R version:

platform       i386-w64-mingw32            
arch           i386                        
os             mingw32                     
system         i386, mingw32               
status                                     
major          3                           
minor          1.2                         
...
language       R                           
version.string R version 3.1.2 (2014-10-31)
nickname       Pumpkin Helmet

I'm trying to use the RODBC package to connect to an MS Access database. I cannot use odbcConnectAccess("location_of_database.accdb") to connect to a database provided by a client. This particular database was created with Access 2013. When I try to connect, I get a variety of warning messages:

Warning messages:
1: In odbcDriverConnect(con, ...) :
  [RODBC] ERROR: state HY000, code -1028, message [Microsoft][ODBC Microsoft     Access Driver] Cannot open database '(unknown)'.  It may not be a database that     your application recognizes, or the file may be corrupt.
2: closing unused RODBC handle 12 
3: In odbcDriverConnect(con, ...) :
  [RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x11a4 Thread 0x798 DBC 0x88e0064 Jet'.
4: In odbcDriverConnect(con, ...) :
  [RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x11a4 Thread 0x798 DBC 0x88e0064 Jet'.
5: In odbcDriverConnect(con, ...) : ODBC connection failed

Interestingly, I can use odbcConnectAccess2007() to connect successfully to databases that were created with Access 2010; however, when I try to use odbcConnectAccess() to connect to those same databases, I get the same errors above.

A Google search of the Error: state 01000, code 1 message above suggests that this page may be helpful, but even after following the steps to alter the HKEY_LOCAL_MACHINE does not work.

While I originally thought that this question was promising, the warning message there relates to "ACE DSN" while the error messages I'm seeing relate to "Jet DSN."

I cannot open the databases I'm trying to access with RODBC with my version of Access as the databases were created with Access 2013 and I have Access 2010 installed.

Can anyone help me trouble shoot why I can't open this database with odbcConnectAccess()?


回答1:


why I can't open this [Access 2013] database with odbcConnectAccess()?

I'm fairly certain that

odbcConnectAccess(<fileSpec>)

is simply shorthand for

odbcDriverConnect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=<fileSpec>')

(i.e., the older "Jet" ODBC driver), and

odbcConnectAccess2007(<fileSpec>)

is simply shorthand for

odbcDriverConnect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<fileSpec>')

(i.e., the newer "ACE" ODBC driver).

The older "Jet" driver cannot work with .accdb files, so odbcConnectAccess2007() would be required. If that throws an "Unrecognized database format" error then it's likely that the database file is damaged.



来源:https://stackoverflow.com/questions/37146494/connecting-32-bit-r-to-a-32-bit-access-database

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