【问题标题】:Connect to MSSQL database with arm linux board using unixODBC and FreeTDS problems使用 unixODBC 和 FreeTDS 问题连接到带有 arm linux 板的 MSSQL 数据库
【发布时间】:2017-04-13 03:18:44
【问题描述】:

我在从我的 arm linux 板查询远程 MSSQL 数据库时遇到问题。 我编译了 unixODBX 和 FreeTDS,将所有文件复制到 arm 板上,其路径与编译它们的 Ubuntu 机器中的路径相同。 我还为 Ubuntu 机器编译了所有内容。 在 Ubuntu 机器上,我可以使用 tsql 和 isql 连接和查询数据库。 在arm board我只能用tsql连接查询,不能用isql。

在 UBUNTU 机器中的 ARM 板编译:

unixODBX:

./configure --prefix=/usr/local/unixodbc-arm --host=arm-linux
make
make install

我删除了 /usr/local/unixodbc-arm/bin/odbc_config 否则我无法编译它。

FreeTDS:

./configure --prefix=/usr/local/freetds-arm --with-unixodbc=/usr/local/unixodbc-arm --host=arm-linux --disable-libiconv
make
make all

我使用了 --disable-libiconv 因为没有这个选项是行不通的。

然后我将“bin”、“lib”和“etc”目录中的文件复制到与 Ubuntu 机器中相同的路径的 arm 板上。

/usr/local/unixodbc-arm/bin
/usr/local/unixodbc-arm/lib
/usr/local/unixodbc-arm/etc

/usr/local/freetds-arm/bin
/usr/local/freetds-arm/lib
/usr/local/freetds-arm/etc

配置文件如下:

freetds.conf:

root@ok335x:/# cat /usr/local/freetds-arm/etc/freetds.conf
#   $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same on a multi-user system
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512

# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[egServer70]
        host = ntmachine.domain.com
        port = 1433
        tds version = 7.0

# Microsoft SQL Server
[SQLEXPRESS]
        host = 192.168.0.195
        port = 1433
        tds version = 7.0
        client charset = UTF-8
root@ok335x:/#

odbcinst.ini:

root@ok335x:/# cat /usr/local/unixodbc-arm/etc/odbcinst.ini
[FreeTDS]
Description=TDS driver (Sybade/MS SQL)
Driver=/usr/local/freetds-arm/lib/libtdsodbc.so
UsageCount=2

root@ok335x:/#

odbc.ini

root@ok335x:/# cat /usr/local/unixodbc-arm/etc/odbc.ini
[SQLEXPRESS]
Description         = Test to FreeTDS
Driver              = FreeTDS
Trace               = Yes
TraceFile           = sql.log
Database            = gti
Servername          = SQLEXPRESS
UserName            = gti_monitor
Password            = gti_monitor
Port                = 1433
ReadOnly            = No
RowVersioning       = No
ShowSystemTables    = No
ShowOidColumn       = No
FakeOidIndex        = No
ConnSettings        =
root@ok335x:/#

tsql 配置:

root@ok335x:/# tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds vdev.0.99.134
             freetds.conf directory: /usr/local/freetds-arm/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: no
                        TDS version: 5.0
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: no
                             GnuTLS: no
root@ok335x:/#

odbcinst 配置:

root@ok335x:/# odbcinst -j
unixODBC 2.3.4
DRIVERS............: /usr/local/unixodbc-arm/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/unixodbc-arm/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/unixodbc-arm/etc/ODBCDataSources
USER DATA SOURCES..: /home/root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
root@ok335x:/#

运行 tsql:

root@ok335x:/# tsql -S SQLEXPRESS -U gti_monitor -P gti_monitor
locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "UTF-8"
1> select * from pressures
2> go
id      datetime        press1  press2
NULL    NULL    1       2
(1 row affected)
1> quit
root@ok335x:/#

运行 isql:

root@ok335x:/# isql SQLEXPRESS gti_monitor gti_monitor -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[ISQL]ERROR: Could not SQLConnect
root@ok335x:/#

这些命令都在具有相同配置文件的 Ubuntu 机器上运行。

有人可以帮忙吗? 非常感谢。

【问题讨论】:

    标签: sql-server linux arm freetds unixodbc


    【解决方案1】:

    来自 isql 手册页...

    isql DSN [用户 [密码]] [选项]

    DSN。数据源名称,用于连接数据库。数据源按顺序在 /etc/odbc.ini 和 $HOME/.odbc.ini 文件中查找,后者覆盖前者。

    带有 -S 的 Tsql 正在使用您的 freetds.conf 文件。但看起来你在 /usr/local/unixodbc-arm/etc/odbc.ini 中有 odbc.ini 文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 2011-02-23
      • 2012-09-09
      • 1970-01-01
      • 2019-12-30
      • 2016-02-02
      • 1970-01-01
      相关资源
      最近更新 更多