isql 可以工作,但 tsql 不行

isql 可以工作,但 tsql 不行

我不擅长使用 Linux,但我可以应付过去。我的最终目标是让 RODBC 在 Shiny 应用程序中运行,以连接到 Oracle 11.1g 数据库。我的第一步是在 Ubuntu VM 上设置 Oracle 客户端。

Ubuntu 版本详情:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

我按照以下说明进行操作:

https://help.ubuntu.com/community/Oracle%20Instant%20Client

安装客户端。我还包含了 odbc 包。我能够相当轻松地让 sqlplus 连接到数据库,但 shiny 中的 RODBC 仍然无法工作。当我尝试在终端窗口中使用 isql 时,它失败了。为了解决这个问题,我安装了 freeTDS。

sudo apt-get install unixodbc unixodbc-dev freetds-dev tdsodbc

我已经将以下文件配置成这样。

--- /etc/odbcinst.ini ---
[Oracle]
Description = Oracle ODBC Connection
Driver = /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1

--- /etc/odbc.ini ---
[STODS1]
Driver = Oracle
ServerName = STODS1
Port = 1521
Database = STODS1
TDS_Version = 7.1

--- /etc/freetds/freetds.conf ---
[global]
tds version = 7.1

[STODS1]
host = stods1.xxxx.xxxxxxx.com
port = 1521
tds version = 7.1

通过此配置,我从不同的命令获得以下响应

isql STODS1 USER PASSWORD -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> 

可以看出,isql 运行良好

但是 osql 失败了。

sudo osql -S "STODS1" -U USER -P PASSWORD
checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
trying /tmp/sql ... no
    trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
    reading /home/oper/.odbc.ini
[STODS1] not found in /home/oper/.odbc.ini
    reading /etc/odbc.ini
[STODS1] found in /etc/odbc.ini
found this section:
[STODS1]
    Driver = Oracle
    ServerName = STODS1
    Port = 1521
    Database = STODS1
    TDS_Version = 7.1
looking for driver for DSN [STODS1] in /etc/odbc.ini
found driver line: "    Driver = Oracle"
driver "Oracle" found for [STODS1] in odbc.ini
found driver named "Oracle"
"Oracle" is not an executable file
looking for entry named [Oracle] in /etc/odbcinst.ini
found driver line: "    Driver = /usr/lib/oracle/12.1/client64
/lib/libsqora.so.12.1"
found driver /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1 for   
[Oracle] in odbcinst.ini
/usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1 is an executable file
Using ODBC-Combined strategy
DSN [STODS1] has servername "STODS1" (from /etc/odbc.ini)
cannot read "/home/oper/.freetds.conf"
/etc/freetds/freetds.conf is a readable file
looking for [STODS1] in /etc/freetds/freetds.conf
found this section:
    [STODS1]
    host = stods1.xxxx.xxxxxx.com
    port = 1521
    tds version = 7.1

Configuration looks OK.  Connection details:

               DSN: STODS1                        
          odbc.ini: /etc/odbc.ini                 
            Driver: /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1
   Server hostname: stods1.xxxx.xxxxxx.com       
           Address: 10.17.16.44                   

Attempting connection as ESG_REPORT ...
+ isql STODS1 ESG_REPORT ESG_REPORT1 -v
[08004][unixODBC][Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the 
connect identifier specified

[ISQL]ERROR: Could not SQLConnect
sed: can't read /tmp/osql.dump.25185: No such file or directory

我不明白为什么 osql 失败而 isql 可以工作,因为看起来 osql 在最后几行中使用了 isql。

tsql 也失败了,通过查看网络和手册,这似乎是由于 TDS 版本造成的,但我已经尝试了我所知道的所有 TDS 版本,包括配置文件中和强制使用 TDSVER。

tsql -S STODS1 -U USER -P PASWORD
locale is "en_GB.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20017 (severity 9):
    Unexpected EOF from the server
    OS error 115, "Operation now in progress"
Error 20002 (severity 9):
    Adaptive Server connection failed
There was a problem connecting to the server

我想我已经包含了大部分信息,但如果还有其他需要,请告诉我。我已经为此工作了 5 天,所以有点厌倦了。任何帮助都很好。

谢谢

答案1

我不明白你为什么使用freetds.conf。它通常用于访问 Sybase 和 Microsoft MS SQL 数据库(参见其主页)。我会隐藏(或至少重命名)该freetds.conf文件并将所有内容放入odbc.ini文件中,如下所示(我让您决定用户 ID/密码是否最好编码在 ini 文件中或其他地方):

--- /etc/odbc.ini ---
[STODS1]
Driver = Oracle
Server = stods1.xxxx.xxxxxxx.com
Port = 1521
Database = STODS1
USER = youroracleusername
PASSWORD = youroracleuserpassword

相关内容