Missing letters of database objects being returned in DBI SQL Server ODBC connection

谁说胖子不能爱 提交于 2019-12-14 03:54:31

问题


Unfortunately, I will not be able to create a good repro for this issue without sharing confidential creds to the database I am having issues with. Hopefully I have enough information below to flag any obvious problems that ODBC experts will understand.

Background

I am running a MacBook Pro with the following specs:

  Model Name:       MacBook Pro
  Model Identifier: MacBookPro15,1
  Processor Name:   6-Core Intel Core i7
  Processor Speed:  2.6 GHz
  Number of Processors: 1
  Total Number of Cores:    6
  L2 Cache (per Core):  256 KB
  L3 Cache: 9 MB
  Hyper-Threading Technology:   Enabled
  Memory:   32 GB
  Boot ROM Version: 1037.0.78.0.0 (iBridge: 17.16.10572.0.0,0)

My ODBC connection is set using FreeTDS as specified here.

The relevant portion of freetds.conf is as follows:

# The POC SQL Server
[POC]
host = 172.22.238.154
port = 1433
tds version = 7.3

My odbcinst.ini file is as follows:

[FreeTDS]
Description=FreeTDS Driver for Linux & SQL Server 
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1

My odbc.ini file is specified as follows:

[POC]
Description         = Connecton to Partners for our children SQL Server 
Driver              = FreeTDS
Servername          = POC

I am trying to make a connection to a SQL Server 2012 database (via VPN) using the following connection information in R:

con <- DBI::dbConnect(odbc::odbc()
                  ,dsn = "POC"
                  ,uid = Sys.getenv("MSSQL_UN")
                  ,database = "CA_ODS"
                  ,pwd = Sys.getenv("MSSQL_PW"))

This generates the following connection object:

> con
  <OdbcConnection> POC2
  Database: CA_ODS
  Microsoft SQL Server Version: 11.00.7001

In general, this connection works as expected. I can query the database using DBI::dbGetQuery(con, "select * from MyTable"), dplyr::tbl(con, MyTable), etc. without issue.

Problem

RStudio, however, is only displaying every other letter of the database objects, and truncating the object names after the first several letters. The following screenshot should illustrate the issue well:

The database I am trying to connect to is called CA_ODS. However, the RStudio object browser is only displaying every other letter of the database name (i.e. the DB is listed as C_D).

This does not appear to be limited to RStudio per se either. While the results of the actual database queries work fine as described above, the returned names from the INFORMATION_SCHEMA appear to match the information in the object browser. Below, when run directly from SQL Server Management Studio, the returned TABLE_CATALOG is CA_ODS, TABLE_SCHEMA is ndacan, etc. When run via the DB connection, however, I get the following.

> DBI::dbGetQuery(con, "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 
TABLE_SCHEMA='ndacan'")
   TABLE_CATALOG TABLE_SCHEMA      TABLE_NAME TABLE_TYPE
1            C_D          naa            f21v BASE TABLE

Question

Any suggestions as to how I can respecify my ODBC connection in R or in my FreeTDS configs to get the full name of database objects returned?


回答1:


As noted in @r2evans comments, this appears to be an issue with odbc, running in R 3.6.0, on a Mac.

In general, it appears that this can be fixed by reinstalling odbc from source install.packages("odbc", type = 'source').

As also noted in the comments, I had recently upgraded my Mac to Catalina. Prior to installing odbc from source I needed to first reinstall XCode using xcode-select --install from my terminal.

As can be seen in the screen capture below, I am now getting the full object names displayed from the odbc connection.



来源:https://stackoverflow.com/questions/58550163/missing-letters-of-database-objects-being-returned-in-dbi-sql-server-odbc-connec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!