Reputation: 75
I am trying to insert some data into a SQL Server database using the pyodbc module.
I have the connection string working.
The following code lists the two columns in the table.
for row in cursor.columns(table='InvUtil'):
print (row.column_name)
I see the following two columns that are in the InvUtil table:
server
termss
I then try to insert data with the following command:
cursor.execute("INSERT INTO InvUtil(server, termss) values (?, ?)", 'ten', 'eleven')
I get the following error. Seems like it's having issues with the InvUtil table name.
Traceback (most recent call last):
File "SQLpydobc.py", line 61, in <module>
cursor.execute("INSERT INTO InvUtil(server, termss) values (?, ?)", 'ten', 'eleven')
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]**Invalid object name 'InvUtil'**. (208) (SQLExecDirectW)")
I expect the script to run without errors. I have a commit command later in the script so should see data in the columns.
Upvotes: 4
Views: 12521
Reputation: 51924
Perhaps specify the full table name with schema/db as in dbo.InvUtil
?
Or perhaps specify the default database name in the connection string (Database=dbo
or InitialCatalog=dbo
).
Upvotes: 3