Python: Pyodbc Execute Stored Procedure With Parameters
I'm having trouble executing a SQL Server stored procedure with Python 3.4. I'm importing Pyodbc to create the connection and have a few lines that are supposed to sent data to a s
Solution 1:
I think what's missing is the commit. Either run the commit method against the cursor:
cursor.execute(sql, params)
cursor.commit()
or set autocommit=True
when the connection is created as in the other answers offered. That connection is used to create the cursor, so the autocommit behavior is inherent to it when the execute()
is called:
cnxn = pyodbc.connect(driver="<driver>", server="<server>",
database="<database>", uid="<username>", pwd="<password>",
autocommit=True)
Solution 2:
I found that the problem was caused by not having autocommit turned on. Pyodbc has autocommit set to False by default.
To enable autocommit, you can declare the connection like:
cnxn = pyodbc.connect(driver="<driver>", server="<server>", database="<database>", uid="<username>", pwd="<password>", autocommit=True)
Solution 3:
Params are usually passed as a tuple, so
params = (irow[0], irow[15], irow[2], irow[6])
should work
Post a Comment for "Python: Pyodbc Execute Stored Procedure With Parameters"