0

I have a SQL Server deployment script running from visual studio that gives me the error:

Error SQL01268: .Net SqlClient Data Provider: Msg 1828, Level 16, State 5, Line 1 The logical file name "myDB" is already in use. Choose a different name.

However, when I go into SSMS and try and drop this database, I get the error:

Cannot drop the database 'myDB', because it does not exist or you do not have permission.

Can anyone help me understand where this phantom filename is already stored so that I can delete it?

Thanks.

6
  • Some discussion about this error message: social.msdn.microsoft.com/Forums/en-GB/vstsdb/thread/… Commented Sep 23, 2011 at 20:53
  • @Marc B yes there are some good points there - I assumed that the intention really was to drop the database, but it might not be. Commented Sep 23, 2011 at 20:55
  • The intention is to rebuild it from a database project. Commented Sep 23, 2011 at 20:57
  • If it is another user attached to myDB, you can use the MSSMS activity monitor to see which connection/user is on that DB. Commented Sep 23, 2011 at 20:58
  • @MarcB - I stopped and then restarted SQL Server. Seems like that would've addressed another connection, no? Commented Sep 23, 2011 at 21:03

2 Answers 2

4

The second error message states that the database cannot be dropped because other sessions are currently connected to it. In order to kick all the users out, you can add this to your deployment script or run it manually before deploying. The USE command is to make sure there isn't a race condition when you are the one who's connected.

USE [master];
GO
ALTER DATABASE myDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
DROP DATABASE myDB;
GO
Sign up to request clarification or add additional context in comments.

11 Comments

User does not have permission to alter database 'myDB', the database does not exist, or the database is not in a state that allows access checks.
Is that from the deployment script or running manually in SSMS? What version is SQL Server (SELECT @@VERSION;)?
Run manually in SSMS. Microsoft SQL Server 2008 (SP1) - 10.0.2573.0 (X64) Feb 4 2011 11:27:06 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
What does this yield? SELECT user_access_desc, is_read_only, state_desc FROM sys.databases WHERE database_id = DB_ID('myDB');? And are you sure you're running as a user with sufficient permissions to alter/drop/create databases?
I get zero rows in the result. Also, when I refresh the list of databases, this database no longer shows. I'm pretty sure I have unlimited permissions here.
|
0

This error can also occur when trying to generate a database from a script. I was trying to do downgrade a SQL Server 2012 database to 2008 as per this article https://superuser.com/questions/468578/move-database-from-sql-server-2012-to-2008. However, when I ran the script initially, I got this error

The logical file name "emmagarland" is already in use. Choose a different name.

Turns out (after reading this article https://ask.sqlservercentral.com/questions/106577/the-logical-file-name-database-is-already-in-use.html) in my restore script, I hadn't checked and changed the logical file names. I had to ensure the path is correct, and the change the generated name for the log file, else it tries to overwrite the .mdf file with the log and then throws this error. I fixed it by changing the name from xxxxx to xxxxxldf

 CREATE DATABASE [xxxxx] ON  PRIMARY 
 ( NAME = xxxxx', FILENAME = N'C:\Program Files\Microsoft SQL
 Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\xxxxx.mdf' , SIZE =
 14400KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
 ( NAME = N'xxxxxldf', FILENAME = N'C:\Program Files\Microsoft SQL
 Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\xxxxx_log.ldf' ,
 SIZE = 18560KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
 GO

Sounds simple but I couldn't work out why this error was occuring when I was creating a brand new database!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.