Im trying to create a database using pymssql and im getting this error.
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 ??
Python driver for SQL Server - Python driver for SQL Server Connect to a SQL Database using Python on Windows, Linux, or macOS.
A simple database interface for Python that builds on top of FreeTDS to provide a Python DB-API (PEP-249) interface to Microsoft SQL Server. The 2. x branch of pymssql is built on the latest release of FreeTDS which removes many of the limitations found with older FreeTDS versions and the 1. x branch.
The issue was that cur.execute starts a transaction every time, but 'CREATE DATABASE' operation cannot be excuted within a transaction
http://social.msdn.microsoft.com/Forums/pl/adodotnetdataproviders/thread/594ff024-8af6-40b3-89e0-53edb3ad7245
>>> connection.autocommit(True)
>>> cursor = connection.cursor()
>>> cursor.execute("CREATE DATABASE Foo")
>>> connection.autocommit(False)
This to works. Strangely its not documented in pymssql ... hmmm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With