Reputation: 21
import pyodbc
con = pyodbc.connect(connection_string) #connection_string already defined. con works
cur = con.cursor()
cur.execute("CREATE TABLE [schema].[TestTestTest](testcolumn1 int, testcolumn2 int)")
con.commit() #I've also tried cur.commit()
The error points to line 4 with the description:
ProgrammingError: ('42000', '[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]111212;Operation cannot be performed within a transaction. (111212) (SQLExecDirectW)')
Any ideas? Can we not create tables with pyodbc?
Upvotes: 2
Views: 4711
Reputation: 71
cur.execute('commit')
use the above comment, which will resolve your issue
Upvotes: 2