Im trying to create a database using pymssql and im getting this error.
我试图使用pymssql创建一个数据库,我得到这个错误。
cur.execute("CREATE DATABASE %s;" % self.getsql('dbname'), conn)
gives
*** OperationalError: (226, 'CREATE DATABASE statement not allowed within multi-
statement transaction.DB-Lib error message 226, severity 16:\\nGeneral SQL Serve
r error: Check messages from the SQL Server\\n')
What does this mean ??
这是什么意思 ??
1 个解决方案
#1
6
The issue was that cur.execute starts a transaction every time, but 'CREATE DATABASE' operation cannot be excuted within a transaction
问题是cur.execute每次都会启动一个事务,但是在事务中不能执行'CREATE DATABASE'操作
>>> connection.autocommit(True)
>>> cursor = connection.cursor()
>>> cursor.execute("CREATE DATABASE Foo")
>>> connection.autocommit(False)
This to works. Strangely its not documented in pymssql ... hmmm
这是有效的。奇怪的是它没有在pymssql中记录......嗯
#1
6
The issue was that cur.execute starts a transaction every time, but 'CREATE DATABASE' operation cannot be excuted within a transaction
问题是cur.execute每次都会启动一个事务,但是在事务中不能执行'CREATE DATABASE'操作
>>> connection.autocommit(True)
>>> cursor = connection.cursor()
>>> cursor.execute("CREATE DATABASE Foo")
>>> connection.autocommit(False)
This to works. Strangely its not documented in pymssql ... hmmm
这是有效的。奇怪的是它没有在pymssql中记录......嗯