I am attempting to use pyobdc to read data from Excel, and I keep getting the following error when attempting to connect to Excel:
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
System details:
Python 3.10 64bit
Microsoft Excel 64-bit version
ODBC Data Sources 32 & 64 bit ( DSN : Microsoft Excel driver)
Code:
import os
import sys
import time
import pyodbc
ExcelPath=C:\Automation_Code\test\Resources\RunManager.xls
con = ("Driver={Microsoft Excel Driver (*.xls)};DBQ="+ExcelPath+";ReadOnly = True;")
print("Opened Excel successfully")
cnxn = pyodbc.connect(con, autocommit=True)
cursor= cnxn.cursor()
cursor.execute("Select * from ["+SheetName+"$] where Execute ='YES'")
row = cursor.fetchone()
print row
