我刚接触SQL,不太确定如何将R连接到SQL数据库。
我想使用R连接到数据库,但不确定连接字符串是什么。
该数据库不是本地的,而是在服务器上。
我可以使用所有CRAN库,但目前正在使用RODBC
,并且已经知道我可能需要使用以下命令。
library(RODBC)
channel <- odbcDriverConnect("")
或者
library(RODBC)
channel <- odbcDriverConnect("some connection string i need")
或者
library(RODBC)
channel <- odbcDriverConnect('driver=#not sure where to find this;server=#not sure where to find this either;database=#i think this would be the path to the database#;trusted_connection=true')
第一种方法在使用R Gui时会打开用户界面,但由于数据库未存储在本地而是在服务器上,因此无法找到特定的表格。
我目前通过Microsoft SQL Server Management Studio(2008)访问数据库,并且认为我可能能够找到所需的连接字符串,以便访问我需要的所有数据库,所以我想知道在Microsoft SQL Server Management Studio中,我需要去哪里创建/构建/编写正确的连接字符串以访问相关的数据库。
非常感谢任何帮助,如果这是一个基础问题,那么抱歉。
提前致谢。
编辑
以下是组件名称和版本信息的一些额外信息。
Microsoft SQL Server Management Studio 10.0.1600.22 ((SQL_PreRelease).080709-1414 )
Microsoft Data Access Components (MDAC) 2000.085.1132.00 (xpsp.080413-0852)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 8.0.6001.18702
Microsoft .NET Framework 2.0.50727.3623
Operating System 5.1.2600
编辑 2
当我输入以下命令时,也会得到以下输出
> odbcDataSources()
MS Access Database Excel Files
"Microsoft Access Driver (*.mdb, *.accdb)" "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"
dBASE Files
"Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)"