It's late, I'm tired - I hope I am just making a stupid mistake but I can't seem to see it. Can anyone see what I may be doing wrong? If I run the SQL on SQL Server Management studio, it works fine. I can run other SQL statements against the cursor, just not this one.
Thanks in advance
System:
Windows 7, Python 3.4, SQLServer 2008, pypyodbc
Query:
IF EXISTS(SELECT * FROM sys.databases WHERE name='{MyDBName}')
BEGIN
ALTER DATABASE {MyDBName} SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE {MyDBName};
END
CODE:
cursor.execute(query)
cursor.commit()
EXCEPTION:
ex = {IndexError} list index out of range