ODBC从R连接到网络驱动器上的Access DB .accdb文件 [英] ODBC connect from R to Access DB .accdb file on Network Drive

查看:93
本文介绍了ODBC从R连接到网络驱动器上的Access DB .accdb文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络驱动器上有一个.accdb Access DB文件,该文件已映射到本地计算机上的Z:/驱动器.您可以将ODBC连接到此吗?

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?

这是创建ODBC的代码(usrAccessPath是包含文件路径的字符串变量):

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))

此文件路径有效:

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.

推荐答案

如前所述,对带有RODBC的R等MS Access数据库的ODBC调用既接受本地硬盘路径,也接受网络路径(即通用命名约定(UNC)),只要他们遵循Windows 文件名规则.当然,请确保通过将字符加倍来在R中转义反斜杠:

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))

此外,映射到UNC的正确映射的本地驱动器应该可以工作:

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))

这篇关于ODBC从R连接到网络驱动器上的Access DB .accdb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆