I am new to pyodbc.
I am unable to connect to PostgreSQL with the below code -
cnxn = pyodbc.connect('Driver={PostgreSQL35W};Server=dummy.cag.com;Port=5432;Database=postgres;Uid=postgres;Pwd=postgres;')
It throws "pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')" error.
I have already configured the DataSource as in
Even the test connection is successful.
Looking for help in this.
FULL CODE - It is just a simple Program Unit -
import pyodbc as pyodbc
def perform_db_operation():
cnxn = pyodbc.connect('Driver={PostgreSQL35W};Server=dummy.cag.com;Port=5432;Database=postgres;Uid=postgres;Pwd=postgres;')
select_cursor = cnxn.cursor()
sql_select_stmt = "SELECT * from public.gluetable212a"
select_cursor.execute(sql_select_stmt)
result_set = select_cursor.fetchall()
for current_record in result_set:
passenger_id = current_record[0]
age = current_record[1]
fare = current_record[2]
ticket = current_record[3]
# insert_cursor.execute(sql_insert_stmt, emp_name, emp_id)
print(passenger_id, age, fare, ticket)
select_cursor.close()
cnxn.commit()
cnxn.close()
perform_db_operation()
RUN CONSOLE LOG -
C:\Users\KarthikDeepan.Gujulu\PycharmProjects\MyProj\venv\Scripts\python.exe C:/Users/KarthikDeepan.Gujulu/PycharmProjects/MyProj/ICOMP/PyODBCTrail1.py
Traceback (most recent call last):
File "C:/Users/KarthikDeepan.Gujulu/PycharmProjects/MyProj/ICOMP/PyODBCTrail1.py", line 38, in <module>
perform_db_operation()
File "C:/Users/KarthikDeepan.Gujulu/PycharmProjects/MyProj/ICOMP/PyODBCTrail1.py", line 16, in perform_db_operation
cnxn = pyodbc.connect('Driver={PostgreSQL ANSI};Data Source=decheqaperf01v.asg.com;Port=5432;Database=postgres;Uid=postgres;Pwd=postgres;')
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Process finished with exit code 1