0
votes

By accident I have deleted MDF and LDF files from my database directory. Now, each time I start SSMS I have error:

Failed to retrieve data for this request.

Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\LearnCSharp.mdf". Operating system error 2: "2(The system cannot find the file specified.)". (Microsoft SQL Server, Error: 5120)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=10.00.2531&EvtSrc=MSSQLServer&EvtID=5120&LinkId=20476

enter image description here

How to remove database from system in such situation?

2
Can you delete the database from the Management Studio - is it still listed?gotqn
It is not listed there anymore.vico
What's the version of your SQL Management Studio?gotqn
SQL Management Studio V17.3vico

2 Answers

0
votes
use master
go
drop database [LearnCSharp]
go
0
votes

It's not clear from your question if the database is still on your server or it's only memorized as default database for your login or as explicitly specified in SSMS dialog.

First try to drop it:

drop database MyDB

If you get an error that database does not exist, check if it's specified as default database for your login