[Twisted-Python] Is it possible to turn off transactions for adbapi?

markscottwright at gmail.com markscottwright at gmail.com
Thu Mar 18 10:29:27 EDT 2010

I'm trying to get SQL Server 2005 to CREATE DATABASE using twisted.  
However, SQL Server won't allow you to run CREATE DATABASE within a  
transaction (apparently, it's not something sql server can roll back, which  
seems sensible). Which means that the following code results in an error.  
Is there a way to turn transactions off for a query?

def test_simple_create():
password = "xxx"
connection_string = "Driver={SQL Native Client}; Server=(local); UID=sa;  
PWD=%s;" % password
db = adbapi.ConnectionPool("pyodbc", connection_string, cp_noisy=True)
cmd = """CREATE DATABASE atest
ON (NAME=atest, FILENAME='c:\temp\atest', SIZE=64MB)
LOG ON (NAME=atestlog, FILENAME='c:\temp\atestlog', SIZE=64MB)"""
yield db.runOperation(cmd)
except Exception, e:
print e

if __name__ == "__main__":
from twisted.python import log
import sys

2010-03-18 09:28:45-0500 [-] Log opened.
2010-03-18 09:28:45-0500 [-] adbapi connecting: pyodbc ('Driver={SQL Native  
Client}; Server=(local); UID=sa; PWD=xxx;',)
2010-03-18 09:28:45-0500 [-] ('42000', '[42000] [Microsoft][SQL Native  
Client][SQL Server]CREATE DATABASE statement not allowed within  
multi-statement transaction. (226) (SQLExecDirectW)')
2010-03-18 09:28:45-0500 [-] adbapi closing: pyodbc
2010-03-18 09:28:45-0500 [-] Main loop terminated.
2010-03-18 09:28:45-0500 [-]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100318/6a086bbb/attachment.htm 

More information about the Twisted-Python mailing list