I am new to SQL and not too sure how to connect R to an SQL database.
我是SQL新手,不太确定如何将R连接到SQL数据库。
I would like to use R to connect to the database, but am unsure what the string is to be able to do this.
我想使用R连接到数据库,但我不确定字符串是什么能够做到这一点。
The database is not local and is on a server.
数据库不是本地数据库,位于服务器上。
I am open to all CRAN libraries but am currently using RODBC
and have got as far as knowing I will probably need to use the following command(s).
我对所有CRAN库开放,但我目前正在使用RODBC并且知道我可能需要使用以下命令。
library(RODBC)
channel <- odbcDriverConnect("")
OR
要么
library(RODBC)
channel <- odbcDriverConnect("some connection string i need")
OR
要么
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')
The first method opens up a user interface when using it an R Gui, but cannot find the specific table as the databases are not stored locally and are on a server...
第一种方法在使用R Gui时打开用户界面,但由于数据库未存储在本地且位于服务器上,因此找不到特定的表...
I have access to the databases currently using Microsoft SQL Server Management Studio (2008), and feel that I probably will be able to find out the require connection string to be able to access all the databases I need, so I guess my question is where in Microsoft SQL Server Management Studio do I need to go in order to create/build/write the correct connection string to access the relevant databases.
我可以访问当前使用Microsoft SQL Server Management Studio(2008)的数据库,并且觉得我可能能够找到require连接字符串以便能够访问我需要的所有数据库,所以我想我的问题是在哪里在Microsoft SQL Server Management Studio中,我需要去创建/构建/编写正确的连接字符串以访问相关数据库。
Any help would be greatly appreciated, and sorry if this is such a basic question.
任何帮助将不胜感激,如果这是一个基本问题,对不起。
Thanks in advance.
提前致谢。
EDIT
编辑
For some additional information this is the component name and version information
有关其他信息,请参阅组件名称和版本信息
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
EDIT 2
编辑2
I also get the following output when typing the following command
键入以下命令时,我也得到以下输出
> 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)"
1 个解决方案
#1
2
Here is my general method (because I also always forget how to do this)
这是我的一般方法(因为我也总是忘记如何做到这一点)
- Create an empty file, e.g. with Notepad, with extension .udl, e.g SQLS.udl.
- 创建一个空文件,例如使用记事本,扩展名为.udl,例如SQLS.udl。
- Double-click on it; a dialog should open, where you can select provider etc, and can test the connection.
- 双击它;应打开一个对话框,您可以在其中选择提供程序等,并可以测试连接。
- After Ok, open the file and use the provider line; it mostly works.
- 确定后,打开文件并使用提供程序行;它主要起作用。
#1
2
Here is my general method (because I also always forget how to do this)
这是我的一般方法(因为我也总是忘记如何做到这一点)
- Create an empty file, e.g. with Notepad, with extension .udl, e.g SQLS.udl.
- 创建一个空文件,例如使用记事本,扩展名为.udl,例如SQLS.udl。
- Double-click on it; a dialog should open, where you can select provider etc, and can test the connection.
- 双击它;应打开一个对话框,您可以在其中选择提供程序等,并可以测试连接。
- After Ok, open the file and use the provider line; it mostly works.
- 确定后,打开文件并使用提供程序行;它主要起作用。