【问题标题】:Connect to MS SQL Server Database Using isql on Mac在 Mac 上使用 isql 连接到 MS SQL Server 数据库
【发布时间】:2019-12-30 22:28:02
【问题描述】:

总结:tsql 连接,isql 不连接。

详情:我已经尝试了所有我能找到的官方安装指南和 Stack Overflow 问题,但没有一个能带来快乐。我正在尝试使用pyodbc 从我的 Mac (Mohave) 连接到 MS SQL Server 数据库,并最终连接到 Xubuntu 16.04 虚拟机。在进入 Python 之前,我只想对连接进行故障排除。问题是,我看到的大多数文档都缺少重要的细节,例如“我应该在用户名和密码中使用引号吗?”或者,“我应该在用户名中包含域吗?”如果我应该在用户名中包含域,“我应该转义反斜杠字符吗?”

这是我当前的设置:tsql -C 产生

Compile-time settings (established with the "configure" script)
                            Version: freetds v1.1.11
             freetds.conf directory: /usr/local/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.3
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes

/usr/local/etc/freetds.conf的内容是:

#
# This file is installed by FreeTDS if no file by the same 
# 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 = auto

    # 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

    # To reduce data sent from server for BLOBs (like TEXT or
    # IMAGE) try setting 'text size' to a reasonable limit
;   text size = 64512

    # If you experience TLS handshake errors and are using openssl,
    # try adjusting the cipher list (don't surround in double or single quotes)
    # openssl ciphers = HIGH:!SSLv2:!aNULL:-DH

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

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

[my_server]
    host = my_server
    port = 1433
    tds version = 7.3

my_server 是我尝试连接的服务器。 命令tsql -S my_server -U domain\\username -P password,在任何地方都没有引号,连接得很好,结果

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 

FreeTDS 就这么多。对于 ODBC 方面,首先请注意,FreeTDS 显然已经为 ODBC 设置了,因为它在tsql -C 的结果中显示unixodbc: yes。我的/etc/odbcinst.ini 文件包含:

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

我的/etc/odbc.ini 文件包含

[my_server]
Description = "The Location of the EOAM_RA Database"
Driver = FREETDS
Trace = Yes
TraceFile = /tmp/sql.log
Database = my_database
Servername = my_server
UserName = domain\\username
Password = password
Port = 1433
Protocol = 7.3
ReadOnly = No
RowVersioning = No
ShowSystemTables = No
ShowOidColumn = No
FakeOidIndex = No

但是,当我尝试任何版本的 isql -v my_server username password 时,我会感到可怕且毫无帮助

[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect

所以,虽然我当然希望对所有内容都进行正确的设置,以便我可以通过 isql 和最终通过 pyodbc 进行连接,但如果我能回答以下问题,这也会有很大帮助:

  1. 对于我应该输入用户名的每个地方,是否应该在其周围加上引号?
  2. 对于我应该输入用户名的每个地方,我是否应该将其以域作为前缀?
  3. 对于我应该输入用户名的每个地方,如果我确实需要包含我的域,我是否应该在中间转义反斜杠?
  4. 对于服务器,我应该包含引号吗?

非常感谢您的宝贵时间!

【问题讨论】:

    标签: sql-server macos odbc freetds


    【解决方案1】:

    您是否尝试在 freetds.conf 文件中为您的 SQL Server 使用完全限定域名 (fqdn) 后进行连接:

    [my_server]
    host = my_server.<yourdomain.example>
    port = 1433
    tds version = 7.3
    

    【讨论】:

    • tsql 仍然适用于此更改。命令中的引号和域等呢? isql 的错误消息已更改为 [IM002][unixODBC][Driver Manager]Data source name not found and no default driver specified
    • 哈!让它与命令 sudo isql -v my_server domain\\username password 一起工作,没有引号。
    • 能否举例说明 fqdn 的外观?谢谢!
    猜你喜欢
    • 2020-01-03
    • 2013-07-05
    • 2012-08-11
    • 1970-01-01
    • 2013-01-08
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多