I have connected SQL Server with Python using pyodbc module. The script seems to have run correctly, however, I am getting errors when I try to execute my SQL statement.
This is what I have done:
import pandas
import numpy
import pyodbc
conn = pyodbc.connect(
'Driver={SQL Server};'
'Server=test\SQLEXPRESS;'
'Database=test1;'
'Trusted_Connection=yes;'
)
cursor = conn.cursor()
def read(conn):
print("Read")
cursor = conn.cursor()
cursor.execute("select * from table")
for row in cursor:
print(f'row = {row}')
print()
read(conn) #to execute
I am wanting to execute a query that I would normally run within my SQL Server, but in Python:
SELECT * FROM table
This is the error:
ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL
Server]Invalid object name 'Node'. (208) (SQLExecDirectW)")
I am actively researching this.
cursor.fetchAll()