I am trying to connect to a database using pyodbc,following code is working fine on windows,trying to run the same on linux is giving an error as follows,can anyone suggest what is wrong here and how to fix it?
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
Error:-
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')
sudo gedit /etc/postgresql/9.3/main/postgresql.conf
.
uncomment and change listen_addresses
from localhost
to *
Next:
`sudo gedit /etc/postgresql/9.3/main/pg_hba.conf`
change 127.0.0.1/32 to 0.0.0.0/0
in the line:
`host all all 127.0.0.1/32 trust`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.