methew / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Drop database failed #370

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Drop database by pyodbc

What is the expected output? What do you see instead?
Expect that SQL database to be dropped but it's not.
(Error:42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot 
drop database "db_mydatabase" because it is currently in use. (3702) 
(SQLExecDirectW)')

I tried SQL management studio GUI to drop the database and it works.

What version of the product are you using? On what operating system?
pyodbc-3.0.7.win32-py2.7.exe / Windows Server 2008 R2

Please provide any additional information below.

ConnectionStr='DRIVER={SQL 
Server};SERVER='+SQLserverIP+';DATABASE='+DATABASE_name+';UID='+UID+';PWD='+PWD

sqlconn=pyodbc.connect(ConnectionStr,autocommit=True)
cur=sqlconn.cursor()
cur.execute("DROP DATABASE "+ DATABASE_name)
sqlconn.close()

Original issue reported on code.google.com by s961...@gmail.com on 12 Jun 2014 at 10:42

GoogleCodeExporter commented 9 years ago
I have fix it, it was my mistake.

I should establish the connection with master database, not the target database.

Thanks for yor help.

Original comment by s961...@gmail.com on 12 Jun 2014 at 11:04