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

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? @defer.inlineCallbacks def test_simple_create(): try: 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 finally: db.close() reactor.stop() if __name__ == "__main__": from twisted.python import log import sys test_simple_create() log.startLogging(sys.stdout) reactor.run() === 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 [-]

Hi Mark, On Thu, 2010-03-18 at 14:29 +0000, markscottwright@gmail.com wrote:
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?
First, you may be better off finding a SQL Server list. FWIW, and not a twisted solution per se, if the SQL server and your twisted server are in a secured network you can send an http msg with your create database statement. This solution requires a webserver (IIS) running on the sql server box and some configuration (a virtual directory IIRC). This solution will work from a non-windows OS. For more complicated queries, taking the ODBC black box out of the equation makes optimization simpler (or even possible). LMA (Luvin my acronyms). George -- George Pauly Ring Development www.ringdevelopment.com

Hey - ! was wrong. It's actually easy, just specify "autocommit=True" in your call to adbapi.ConnectionPool(...) and runOperation can execute "create database". On Thu, Mar 18, 2010 at 10:53 AM, George Pauly <george@ringdevelopment.com> wrote:
Hi Mark,
On Thu, 2010-03-18 at 14:29 +0000, markscottwright@gmail.com wrote:
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?
First, you may be better off finding a SQL Server list.
FWIW, and not a twisted solution per se, if the SQL server and your twisted server are in a secured network you can send an http msg with your create database statement. This solution requires a webserver (IIS) running on the sql server box and some configuration (a virtual directory IIRC).
This solution will work from a non-windows OS. For more complicated queries, taking the ODBC black box out of the equation makes optimization simpler (or even possible).
LMA (Luvin my acronyms).
George
-- George Pauly Ring Development www.ringdevelopment.com
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Mark Wright markscottwright@gmail.com
participants (3)
-
George Pauly
-
Mark Wright
-
markscottwright@gmail.com