Linux + pyodbc + freetds + UNIXODBC connection Sybase

Source: Internet
Author: User
Tags locale sybase

Operating system is RHEL6.2

  1. Installing UNIXODBC and dependent packages

    Yum-y install gcc gcc-c++ unixodbc unixodbc-devel python-devel

  2. Installing FreeTDS

    Tar XF freetds-stable.tgz

    CD freetds-0.91/

    ./configure--prefix=/usr/local/freetds--with-unixodbc=/usr/--with-tdsver=5.0

    Make

    Make install

  3. Configure FREETDS and use TSQL to test the connection

    Vim/usr/local/freetds/etc/freetds.conf

    Add the following content:

    [Sybase]

    Host = IP Address

    Port = port number

    TDS Version = 5.0

    Client CharSet = UTF-8

    Specific IP and port number to be replaced by individual

    To test the connection:

    /usr/local/freetds/bin/tsql-s sybase-u user name-p password

    If the following appears, or something like this, indicates a successful connection, you can execute some SQL statements to try

    Locale is "En_us.utf8"

    Locale CharSet is "UTF-8"

    Using default CharSet "UTF-8"

    1>

  4. Configure UNIXODBC and test isql

    Create the driver template file 1.txt content as follows:

    [TDS]

    Description = Sybase

    Setup =/usr/lib/libtdss.so

    Driver64 =/usr/local/freetds/lib/libtdsodbc.so

    Driver =/usr/local/freetds/lib/libtdsodbc.so

    SETUP64 =/usr/lib64/libtdss.so

    FileUsage = 1

    Usagecount = 2

    Then use Odbcinst to install the driver:

    Odbcinst-i-d-f 1.txt

    After the execution, you can check the/etc/odbcinst.ini, if you can see the contents of the TDS, the configuration is not a problem

    You can also check the drive with Odbcinst-q-D

    Create a template file for the data source with the following contents:

    [Xiaosu]

    Driver = TDS

    Descrption = Sybase Server

    Trace = No

    Server = IP Address

    Database = Databases

    Port = port number

    The DATABASE,IP address and port number are replaced with the one you need.

    Odbcinst-i-s-f 2.txt

    After execution, the. odbc.ini file is generated in the user's home directory, and vim ~/.odbc.ini check the file contents. You can also check for available data sources with odbcinst-q-s

    Test connection with isql: isql-v xiaosu user name password

    If the following appears, the connection is successful.

    +---------------------------------------+

    |                            connected! |

    | |

    | sql-statement |

    | Help [TableName] |

    | Quit |

    | |

    +---------------------------------------+

    Sql>

  5. Compiling and installing PYODBC

    Unzip Pyodbc-3.0.7.zip

    CD pyodbc-3.0.7

    Python setup.py Install

  6. Test PYODBC Connection

    Create a new xiaosu.py content as follows:

  7. Import Pyodbcconn=pyodbc.connect ("DSN=XIAOSU;    Uid=uid;pwd=password ") Cursor=conn.cursor () cursor.execute (" Select name from sysobjects where type = ' U ' ") for I in cursor: Print I

    Python xiaosu.py If you can print all the tables in the database, it's a success.

Linux + pyodbc + freetds + UNIXODBC connection Sybase

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.