Having Troubles with UnixODBC, FreeTDS, and PyODBC

后端 未结 1 831
执念已碎
执念已碎 2020-12-09 06:07

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

相关标签:
1条回答
  • 2020-12-09 06:25

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

    /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

    # 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

    # 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
    

    Then test your connection:

    isql mssql username password
    

    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>
    
    0 讨论(0)
提交回复
热议问题