UnixODBC、FreeTDS 和 PyODBC 出现问题 [英] Having Troubles with UnixODBC, FreeTDS, and PyODBC

查看:59
本文介绍了UnixODBC、FreeTDS 和 PyODBC 出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让这三者和谐地协同工作.我想我会列出所有的各种配置,以及测试代码,看看是否有一双新鲜的眼睛可以看出我的愚蠢.

I am having great difficulty getting all three of these to work together in harmony. I guess I'll list all the various configurations, along with the test code to see if a pair of fresh eyes can realize my stupidity.

我正在运行 12.04 Ubuntu Server,我正在尝试连接到 MSSQL Server 2008 并最终将它与 PyODBC 一起使用.

I'm running 12.04 Ubuntu Server and I'm trying to connect to a MSSQL Server 2008 and end up using it with PyODBC.

但是,当刚放入时

tsql -S T2 -U Foo -P Bar

我明白了

1>
2>
3>
4>
5>
6>
7>
8>
9>
10>
11>

等等

无论如何,如果有人能够提供帮助(如果您能帮我清除这种阴霾,我将永远感激不尽),这是我目前的配置.

Anyway, if anyone would be able to help (and I would be eternally grateful if you can clear me of this haze), here are my current configurations.

这是我的/etc/odbc.ini

This is my /etc/odbc.ini

[ODBC Data Sources]
odbcname     = MySQL
T2           = MSSQL

[odbcname]
Driver       = /usr/lib/odbc/libmyodbc.so
Description  = MyODBC 3.51 Driver DSN
SERVER       = Foobar
PORT         = 3306
USER         = Foo
Password     = Bar
Database     = Foobar
OPTION       = 3
SOCKET       =

[T2]
Driver       = FreeTDS
Description  = ODBC connection via FreeTDS
SERVER       = FOOBAR
PORT         = 1433
USER         = Foo
Password     = Bar
Database     = Foobar
OPTION       = 3
SOCKET       =

[Default]
Driver       = /usr/local/lib/libmyodbc3.so
Description  = MyODBC 3.51 Driver DSN
SERVER       = FOOBAR
PORT         = 3306
USER         = foo
Password     = bar
Database     = FOOBAR
OPTION       = 3
SOCKET       =

以下是我的/etc/odbcinst.ini

The following is my /etc/odbcinst.ini

[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so
CPTimeout=
CPReuse=
FileUsage=1

以下是我的freetds.conf

The following is my 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 = 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

[T2]
        host = FOOBAR
        port = 1433
        tds version = 7.0
        client charset = UTF-8
        text size = 20971520
[global]
        # TDS protocol version
        tds version = 7.0

我的 Python 测试文件只是为了更好的衡量

And my Python test file just for good measure

import pyodbc
import sys 

try:
    #tempsystrends = pyodbc.connect('DRIVER=FreeTDS;SERVER=FOOBAR;PORT=1433;DATABASE=T2;UID=FOO;PWD=bar;TDS_Version=7.0;')
    cursor = tempsystrends.cursor()
except pyodbc.Error as e:
        print "Error: %s" % (e.args[1])
        sys.exit(1)

推荐答案

我使用 UnixODBC 通过 PHP 连接到各种数据库,这是我对 Microsoft SQL Server 的配置:

I connect to various databases via PHP using UnixODBC, here is my configuration for a Microsoft SQL Server:

/etc/odbc.ini

/etc/odbc.ini

# Define a connection to a Microsoft SQL server
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description             = MSSQL Server
Driver                  = freetds
Database                = XXXXXX
ServerName              = MSSQL
TDS_Version             = 8.0

/etc/odbcinst.ini

/etc/odbcinst.ini

# Define where to find the driver for the Free TDS connections.
[freetds]
Description     = MS SQL database access with Free TDS
Driver          = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup           = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount      = 1

/etc/freetds/freetds.conf

/etc/freetds/freetds.conf

# The basics for defining a DSN (Data Source Name)
# [data_source_name]
#       host = <hostname or IP address>
#       port = <port number to connect to - probably 1433>
#       tds version = <TDS version to use - probably 8.0>

# Define a connection to the Microsoft SQL Server
[mssql]
        host = XXXXXX
        port = 1433
        tds version = 8.0

然后测试您的连接:

isql mssql username password

根据您的环境,您的 username 可能必须采用以下格式:域\用户名

Depending on your environment your username might have to be in the format: domain\username

发出命令后,您应该看到如下内容:

After issuing the command you should see something like:

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

这篇关于UnixODBC、FreeTDS 和 PyODBC 出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆