Thanks for everyoneâs feedback.
library(RODBC)
con = odbcConnect("SQLServer2012")
orders1 = sqlFetch(con,"dbo.orders")
odbcClose(con)
Allowed me to close the connection properly. Thanks.
However, I still cannot figure out how to connect to the second database
and table.
library(RODBC)
>con2 = odbcConnect("[sportsDB].dbo.sports")
Warning messages:
1: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :
ODBC connection failed
>con2 = odbcConnect("[sportsDB].[dbo].sports")
Warning messages:
1: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :
ODBC connection failed
>con2 = odbcConnect("[sportsDB].[dbo].[sports]")
Warning messages:
1: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :
ODBC connection failed
>con3 = odbcConnect("SQLServer2012")
>orders3 = sqlFetch(con3, "sportsDB.dbo.sports")
Error in odbcTableExists(channel, sqtable) :
âsportsDB.dbo.sportsâ: table not found on channel
On 6/30/2014 1:34 AM, Peter Crowther wrote:
> On 30 June 2014 02:44, Ira Sharenow <[email protected]> wrote:
>> I wish to query tables that are NOT in the default SQL Server 2012 database.
>> Now for the problem. I also want to read in the table dbo.sports. That
>> table is in the database sportsDB. I did not see any way to do so from
>> within R.
> Can you not use sportsDB.dbo.sports to reference the table?
>
> In general, table reference syntax is [ [ [ serverName '.' ]
> databaseName '.' ] [schema ] '.' ] tableName, where the names need
> only be surrounded by [...] if they are not valid SQL Server
> identifiers. Many people may suggest you reference
> [sportsDB].[dbo].[sports]; this is unnecessary verbiage.
>
> Cheers,
>
> - Peter
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.