MS SQL Express: DROP DATABASE exception.

620 views
Skip to first unread message

CinnamonDonkey

unread,
Oct 23, 2009, 9:44:04 AM10/23/09
to pyodbc
Hi All,

I am trying to write a bit of code to delete a database in a MS SQL
Express server. The code looks something like this:


import pyodbc

cxn = pyodbc.connect('DRIVER={SQL Server};SERVER=MYSERVER
\SQLEXPRESS;')
cxn.execute("DROP DATABASE TestDatabase")
cxn.commit()
cxn.close()

When I run this code I get the following exception:

pyodbc.ProgrammingError: ('42000', '[42000][Microsoft][ODBC SQL Server
Driver][SQL Server]DROP DATABASE statement cannot be used inside a
user transaction. (574)(SQLExecDirectW))

Could one of you clever bods please advice me as to what I am doing
wrong and how I go about solving the problem.

Thank You,
Shaun Hewitt




Alec Shaner

unread,
Oct 23, 2009, 1:35:37 PM10/23/09
to pyo...@googlegroups.com
Try:

cxn = pyodbc.connect('DRIVER={SQL
Server};SERVER=MYSERVER\SQLEXPRESS;', autocommit=True)
cxn.execute("DROP DATABASE TestDatabase")
cxn.close()

CinnamonDonkey

unread,
Oct 26, 2009, 4:26:13 AM10/26/09
to pyodbc
Excellent! That done the job :)

Thank you!
-Shaun


On 23 Oct, 14:44, CinnamonDonkey <cinnamondon...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages