0

我正在尝试使用 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')
4

1 回答 1

0

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

取消注释并 listen_addresses从更改localhost*

下一个:

`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`
于 2014-06-06T01:18:11.503 回答