linux上的pyodbc连接失败

时间:2014-06-05 22:35:11

标签: python pyodbc pypyodbc

我正在尝试使用pyodbc连接到数据库,以下代码在Windows上工作正常,尝试 在linux上运行相同的错误如下,有人可以在这里提出错误以及如何修复它吗?

import pypyodbc as pyodbc
component_id=argv[1]
print "COMPONENT ID: " + component_id
server_name='odsdb.company.com'
database_name='ODS'
cnx = pyodbc.connect("DRIVER={SQL Server};SERVER="+server_name+";DATABASE="+database_name)
db_cursor=cnx.cursor()

vi /etc/odbcinst.ini

[PostgreSQL ANSI]
Description             = PostgreSQL ODBC driver (ANSI version)
Driver          = psqlodbca.so
Setup           = libodbcpsqlS.so
Debug           = 0
CommLog         = 1
UsageCount              = 1

[PostgreSQL Unicode]
Description             = PostgreSQL ODBC driver (Unicode version)
Driver          = psqlodbcw.so
Setup           = libodbcpsqlS.so
Debug           = 0
CommLog         = 1
UsageCount              = 1

错误: -

  File "build_ver.py", line 11, in <module>
    cnx = pyodbc.connect("DRIVER={SQL Server};SERVER="+server_name+";DATABASE="+database_name)
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 2434, in __init__
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 2483, in connect
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 988, in check_success
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 964, in ctrl_err
pypyodbc.Error: (u'IM002', u'[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified')

1 个答案:

答案 0 :(得分:0)

sudo gedit /etc/postgresql/9.3/main/postgresql.conf

取消注释并将listen_addresseslocalhost更改为*

下一步:

`sudo gedit /etc/postgresql/9.3/main/pg_hba.conf` 

更改127.0.0.1/32 to 0.0.0.0/0     在行:

 `host    all             all             127.0.0.1/32            trust`