在 Mac 上使用 isql 连接到 MS SQL 服务器数据库
Connect to MS SQL Server Database Using isql on Mac
总结: tsql
连接而 isql
不连接。
详细信息: 我已经尝试了我能找到的所有官方安装指南和 Stack Overflow 问题,但其中 none 产生了快乐。我正在尝试从我的 Mac (Mohave) 连接到 MS SQL 服务器数据库,并最终使用 pyodbc
连接到 Xubuntu 16.04 虚拟机。在进入 Python 之前,我只想解决连接问题。问题是,我看到的大部分文档都缺少重要的细节,例如 "Should I use quotes in usernames and passwords?" 或 "Should I include the domain in the username?" 如果我应该包括域和用户名,"Should I escape the backslash character?"
这是我当前的设置: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
,但如果我能得到以下问题的答案,它也会有很大帮助以下问题:
- 对于我应该输入用户名的每个地方,它是否应该用引号引起来?
- 对于每个应该输入用户名的地方,我是否应该在其前面加上域名?
- 对于我应该输入用户名的每个地方,如果我确实需要包含我的域,我是否应该转义中间的反斜杠?
- 对于服务器,我应该包含引号吗?
非常感谢您的宝贵时间!
在 freetds.conf 文件中为您的 SQL 服务器使用完全限定域名 (fqdn) 后,您是否尝试过连接:
[my_server]
host = my_server.<yourdomain.example>
port = 1433
tds version = 7.3
总结: tsql
连接而 isql
不连接。
详细信息: 我已经尝试了我能找到的所有官方安装指南和 Stack Overflow 问题,但其中 none 产生了快乐。我正在尝试从我的 Mac (Mohave) 连接到 MS SQL 服务器数据库,并最终使用 pyodbc
连接到 Xubuntu 16.04 虚拟机。在进入 Python 之前,我只想解决连接问题。问题是,我看到的大部分文档都缺少重要的细节,例如 "Should I use quotes in usernames and passwords?" 或 "Should I include the domain in the username?" 如果我应该包括域和用户名,"Should I escape the backslash character?"
这是我当前的设置: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
,但如果我能得到以下问题的答案,它也会有很大帮助以下问题:
- 对于我应该输入用户名的每个地方,它是否应该用引号引起来?
- 对于每个应该输入用户名的地方,我是否应该在其前面加上域名?
- 对于我应该输入用户名的每个地方,如果我确实需要包含我的域,我是否应该转义中间的反斜杠?
- 对于服务器,我应该包含引号吗?
非常感谢您的宝贵时间!
在 freetds.conf 文件中为您的 SQL 服务器使用完全限定域名 (fqdn) 后,您是否尝试过连接:
[my_server]
host = my_server.<yourdomain.example>
port = 1433
tds version = 7.3