I have setup a connection in R:
conn <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "...",
Database = "AdventureWorks2012")
The default ODBC driver is AdventureWorks2012. I can see the data set just fine and for example, the following code runs without a problem:
dbGetQuery(conn, "SELECT TOP 10 * FROM Person.Person")
On the other hand, running
dbReadTable(conn, "Person.Person")
yields:
Error: <SQL> 'SELECT * FROM "Person.Person"'
nanodbc/nanodbc.cpp:1587: 42S02: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Person.Person'.
Similary, running
data <- tbl(conn, "Person.Person")
yields:
Error: <SQL> 'SELECT *
FROM "Person.Person" AS "zzz12"
WHERE (0 = 1)'
nanodbc/nanodbc.cpp:1587: 42S02: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Person.Person'.
Also, I am stumped as to WHERE (0 = 1)
: cannot figure out where it comes from!!!
(1) The table does exist in the database. (2) I have qualified the name with the correct Schema. (3) I have set the default database in ODBC to AdventureWorks2012.
I would appreciate your help and insight. Thank You ...
> tableList <- dbListTables(conn)
> tableList
[1] "AWBuildVersion"
[2] "DatabaseLog"
[3] "DeleteExample"
[4] "EmployeeSales"
[5] "ErrorLog"
[6] "PersonCross"
[7] "PhoneCross"
[8] "Department"
[9] "Employee"
[10] "EmployeeDepartmentHistory"
[11] "EmployeePayHistory"
[12] "JobCandidate"
[13] "Shift"
[14] "Address"
[15] "AddressType"
[16] "BusinessEntity"
[17] "BusinessEntityAddress"
[18] "BusinessEntityContact"
[19] "ContactType"
[20] "CountryRegion"
[21] "EmailAddress"
[22] "Password"
[23] "Person"
[24] "PersonPhone"
...
> dbReadTable(conn, "Person")
Error: <SQL> 'SELECT * FROM "Person"'
nanodbc/nanodbc.cpp:1587: 42S02: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Person'.