Monday, March 10, 2008

INSERT problems via pyodbc

This is really stupid, but I just wasted about an hour of dev time trying to figure out why my INSERT statements weren't working from a Python script using pyodbc even though SELECTs were fine. As it turns out, they were getting rolled back because I wasn't explicitly committing the transactions and hadn't set the AUTOCOMMIT option to true for the connection.

So if you happen to search for "pyodbc INSERT problems" (as I did), hopefully you'll stumble across this (as opposed to nothing, which is what I found) and slap yourself in the head (as I did).

7 comments:

Volodymyr said...

Thanks, this was useful. I ran into the same problem.

SooW said...

Thanks :) Pretty nice Google rank, BTW.

BenDog said...

thanks for this.

Bob Broderick said...
This comment has been removed by the author.
UGMA said...

thanks, so good

Robert said...

uh thanks for showing us the code

Ira Pfeifer said...

Seriously, Robert? pyodbc.connect() has a pretty simple signature.

But in the interest of completeness, here you go:

pyodbc.connect('DSN=test', autocommit=True)