I encountered this problem when using pymssql to connect to SQL Server. pymssql.OperationalError: (3702, b'Cannot drop database "XXX" because it is currently in use.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n') 1 Programmer: cursor = conn.cursor() conn.autocommit(True) cursor.execute('CREATE DATABASE XXX ON (NAME=\'XXX_Data\', FILENAME=\'{}\\XXX.mdf\', SIZE=5 MB, MAXSIZE=50 MB, FILEGROWTH=5%) LOG ON (NAME=\'XXX_Log\',FILENAME=\'{}\\XXX_Log.ldf\',SIZE=1 MB,MAXSIZE=5 MB,FILEGROWTH=1 MB)'.format(dir, dir)) cursor.execute('USE XXX CREATE TABLE xxx ( xxxxxxx )') cursor.execute('DROP TABLE xxx') cursor.execute('USE XXX DROP DATABASE XXX') I turned on autocommit before operating the database, and then found that if I performed other operations on the database between the CREATE DATABASE and DROP DATABASE statements, the above error would occur when DROP DATABASE. After checking the relevant information, I found that the reason is that the database itself is used incorrectly when deleting the database: "USE XXX", in order to delete successfully, you need to change the USE to "USE MASTER": cursor.execute(cursor) cursor.execute('USE MASTER DROP DATABASE XXX') 1 Then the deletion is successful. Another method on the Internet is to add the following statement to roll back the database to the initial state, the actual test did not affect me, the reason is unknown. use master go alter database database_name set single_user with rollback immediate
Moved online, effective
Similar Posts:
- Solution to the error of ora-06550 pls-00103 when Django connects Oracle to run PLSQL statement
- Solve Python MySQL insert int data error: typeerror% d format: a number is required, not str
- ORA-00980 synonym translation is no longer valid
- Solution of pymssql installation error under win
- (20002, b’DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (127.0.0…
- The solution of the table is full in MySQL
- Database Backup Error: mysqldump: Got error: 1146: Table ‘enwei_hq.tb_classification’ doesn’t exist when using LOCK TABLES
- MySQL master-slave synchronization error 1507
- MySQL exclude error 1114 holmium HY000 41 holmium“
- Ora-01653: table a cannot be extended by 1024 (in table space ABC)