Unable to drop Serverless database in Synapse Studio - database

From Synapse Studio, I created the database [tbfb_Test_ExtermalTables] in the serverless Built-in SQL pool, but can't delete/drop it now. There is no connection to this database. Monitor > SQL Request > all are either Complete or Failed.
drop DATABASE [tbfb_Test_extermalTables]
5:06:48 PM
Started executing query at Line 6
Cannot drop database "tbfb_Test_extermalTables" because it is currently in use.
Total execution time: 00:00:20.764
use master;
go
ALTER DATABASE [tbfb_Test_ExtermalTables] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
Go
5:10:04 PM
Started executing query at Line 5
Changed database context to 'master'.
SINGLE_USER is not supported for ALTER DATABASE.
Total execution time: 00:00:00.634

Related

How to permanently set database to SINGLE_USER Mode?

I implemented log shipping using dbatools command and was testing it out today. What ive noticed is when i query the restored/standby database, like a select on a table, the restore of transaction log fails until i disconnect from the instance.
Message
2021-09-24 23:00:23.60 *** Error: Could not apply log backup file '\\devops\c$\Users\devops_user\Documents\DBLogShipping\Backups\LogShippingFiles\test12345\test12345_20210924225000.trn' to secondary database 'test12345'.(Microsoft.SqlServer.Management.LogShipping) ***
2021-09-24 23:00:23.60 *** Error: Exclusive access could not be obtained because the database is in use.
RESTORE LOG is terminating abnormally.(.Net SqlClient Data Provider) ***
I found out that by setting the database to SINGLE_USER mode:
USE master
GO
ALTER DATABASE test12345
SET SINGLE_USER
--This rolls back all uncommitted transactions in the db.
WITH ROLLBACK IMMEDIATE
GO
the restore job will actually work fine whilst querying the database, so no need to disconnect from the server. I mean that is great! However, when i disconnected and reconnected later to the instance, I saw the SINGLE_USER mode disappeared...it looks like it reverted back to the default multi_user mode?
Is there a way to permanently have the database set in SINGLE USER mode?

User 'dbo' does not have permission to run DBCC freesystemcache. AZURE

I created SQL database on Azure. I tried to clear cache from SQL Server Management
using:
DBCC FREEPROCCACHE, DBCC FREESYSTEMCACHE ('dbo')
Unfortunately I am not successfull.
I get the error
User 'dbo' does not have permission to run DBCC freesystemcache.
How is this possible, as dbo is the owner of a database?
Like #MJH stated in the previous answer, executing this requires ALTER SERVER STATE permissions. The article DBCC FREESYSTEMCACHE (Transact-SQL) also clearly shows it does not apply to Azure SQL Database.
Since Azure SQL is a managed service, this will be handled by the platform.
Extra: see ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)
Instead of DBCC FREEPROCCACHE please try the following statement:
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE
The ALTER DATABASE SCOPED CONFIGURATION statement requires ALTER ANY DATABASE SCOPE CONFIGURATION permission on the database. This permission can be granted by a user with CONTROL permission on a database.

user: dbo unable to drop database

I have a SQL agent job whereby we do a restore of a full backup of production data on a nightly basis. We are setting up a new server and when I attempt to run the job on the new server I receive an error on the job of
3701 - Cannot drop database because it does not exist or you do not have permission.
This is confounding me because we are using the dbo user to accomplish this step and the database is listed in sys.databases catalog view. I have tried altering the database to put it into single_user to no avail.
The first step of the job kills all connections and that passes. I am not sure where this error is coming from because everything looks in accord to me. We can also drop the database manually through logging in as the sa.

SQL Server 2012 unable to turn off Snapshot Isolation

Using the code below I'm unable to turn off snapshot isolation. I'm using a SQL Server 2012 box. I can create brand new empty db, turn snapshot isolation on, but I can't turn it back off.
The "allow_snapshot_isolation OFF" line just spins it's wheels.
ALTER DATABASE SNAP SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE SNAP SET allow_snapshot_isolation OFF
ALTER DATABASE SNAP SET read_committed_snapshot off
ALTER DATABASE SNAP SET MULTI_USER
Are you sure that no other transactions were ran on the database? Remeber about implicit transactions which are used eg. by JDBC drivers (when you setAutocommit to false).
Snapshot isolation cannot be turn off if any of the previous transactions is pending. This is, because it has to be sure that any other transaction will not try to use previous row versions. However, it is possible to make queries spanning through more than one database so setting snapshot isolation is not only taking care of transaction on one database.
You can check if this is the case by using sp_who2 and SELECT * FROM sys.sysprocessesand searching for your altering process. sp_who2 will be showing that the process is suspended and by using sys.sysprocesses you will probably find out that its lastwaiting type is 'DISABLE_VERSIONING'.
So your solution is to rollback all transactions (or close conections in case of implicit transactions).
Be awared, that if you are using a connection pooling from some program, you may have, for example, 40 implicit transactions opened in two or three dbs. If they were opened after the snapshot mode had been turned on then turning it off will be impossible until they end.
I followed below for the same issue I was getting
USE master;
GO
ALTER DATABASE MYDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE MYDB MODIFY NAME = MYDB_1;
GO
ALTER DATABASE MYDB_1 SET READ_COMMITTED_SNAPSHOT OFF;
GO
ALTER DATABASE MYDB_1 MODIFY NAME = MYDB;
GO
ALTER DATABASE MYDB SET MULTI_USER;
I ran the MSSQL query below to turn off ALLOW_SNAPSHOT_ISOLATION for master database:
ALTER DATABASE master SET ALLOW_SNAPSHOT_ISOLATION OFF;
GO;
Then, I got this error below:
SNAPSHOT ISOLATION is always enabled in this database.
And, I ran the MSSQL query below to turn on READ_COMMITTED_SNAPSHOT for master database:
ALTER DATABASE master SET READ_COMMITTED_SNAPSHOT ON;
GO;
Then, I got this error below:
Option 'READ_COMMITTED_SNAPSHOT' cannot be set in database 'master'.
Because the documentation says below:
The ALLOW_SNAPSHOT_ISOLATION option is automatically set ON in the
master and msdb databases, and cannot be disabled.
Users cannot set the READ_COMMITTED_SNAPSHOT option ON in master,
tempdb, or msdb.

How can I set ALLOW_SNAPSHOT_ISOLATION ON on SQL Server without restarting the DB server?

I'm trying to run the following statement on a SQL server database:
ALTER DATABASE myDB
SET READ_COMMITTED_SNAPSHOT ON
Query Analyzer just keeps spinning and nothing returns. I've read about other people experiencing this problem and that it should normally return fairly quickly, and the only way they've found around it is to restart the SQL Server service. Unfortunately, I don't have that option. Is there any way to get this statement to run without restarting the service?
Looks like my search parameters weren't too good, came up with an answer now. The code below seems to do the trick:
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE myDB SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE myDB SET MULTI_USER;

Resources