Run a ALTER DATABASE command like below before dropping the database:
USE [master]
GO
ALTER DATABASE [databaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE [master]
GO
DROP DATABASE [databaseName]
GO
Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts
Wednesday, November 25, 2015
Monday, June 2, 2014
Cannot drop database because it is currently in use error
We might get following error when we try to drop a database in SQL Server:
"Cannot drop database 'MyDatabaseName' because it is currently in user".
To resolve this error, alter the database first before deleting the database like below..
USE [master]
GO
ALTER DATABASE [MyDatabaseName] set single_user with rollback immediate
DROP DATABASE [MyDatabaseName]
GO
Tuesday, February 21, 2012
Visual Studio Database (VSDB) Project issue with UDF and Views
In Visual Studio 2010, there seems to be a dependency problem with User Defined Functions (UDF) and Views. The deployment script created by the VSDB project always puts UDF before database Views. Consider this scenario, we have a database function which depends on a database view and we have altered both the function and the view. Now, when a deployment script is created for this database project, the altered function is always placed before the alter view statement. Running this script will fail at alter function statement because the dependent view was not altered yet. I could not find any settings in VSDB project to change the sequence order for the build, meaning build my database View first and then the UDF. The only workaround I found was to alter my database View in the pre-deployment script.
Subscribe to:
Posts (Atom)