【发布时间】:2019-12-12 12:34:09
【问题描述】:
我正在尝试通过我的 MacBook 连接到我公司的 SQL Server 数据库,并已按照此处列出的步骤进行操作:https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX,但在执行以下步骤时仍然出现以下错误:
通过运行isql TEST myuser mypassword 检查一切是否正常。您应该看到以下内容:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
我已经验证了以下工作:
使用 tsql 实用程序测试连接,例如tsql -S TEST -U myuser -P mypassword。如果这有效,您应该会看到以下内容:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
odbcinst.ini 和 odbc.ini 配置文件都在同一个目录中。
MacBook-Pro: myname$ odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /Users/myname/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
odbcinst.ini 文件配置:
[FreeTDS]
Description=FreeTDS Driver for Linux & MSSQL
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1
odbc.ini 配置:
[TEST]
Description = Test to SQLServer
Driver = FreeTDS
Servername = ServerName
freetdf.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
# 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
# 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
# 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
[TEST]
host = ServerName
port = 1433
tds version = 7.3
client charset = UTF-8
我的命令和输出:
isql TEST myuser mypass -v
[IM002][unixODBC][Driver Manager]未找到数据源名称且未指定默认驱动程序
[ISQL]错误:无法 SQLConnect
【问题讨论】:
-
您是在告诉我们
tsql -S MYMSSQL ...适合您吗?如果是这样,那么您并没有向我们提供整个故事,因为在您的任何配置文件中都没有名为MYMSSQL的条目。请edit您的问题准确(简洁地)描述您真正在做什么,什么有效,什么无效。 -
另外,
tds version = 8.0也不是无效的。这不会阻止连接,但您应该选择合适的tds version,具体取决于您的 FreeTDS 版本。见本页第二张表:freetds.org/userguide/choosingtdsprotocol.htm -
@GordThompson 我更新了问题 - 不确定这会如何改变任何事情,因为您可以从我的配置文件中推断出我在命令中使用 TEST 而不是 MYMSSQL。
-
@FlipperPA 我将它更新到正确的版本,7.3,但仍然没有运气
-
@dir101 是的,这不能解决这个问题,但它可以让你在路上省去头疼的问题。 :)
标签: python sql-server pyodbc freetds unixodbc