Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

c# - Database already exist. Choose a Different Name using CreateDatabase()

I got an issue and learned something at the same time....

I created a DBML from an existing server database.

From the DBML I wanted to create local database (an .mdf file). I created the database using DataContext.CreateDatabase("C:xxxx.mdf") .

Then I decided to delete it (MANUALLY, which is a bad thing evidentally) because when I try to recreate the database with the same name (eventhough the files are deleted), I get the error Database already exist. Choose a Different Name using CreateDatabase()

I tried looking through the registry, no luck... I tried searching the whole hard drive for the file.. no luck.

After googling, I found that you delete a database that was created with CreateDatabase() with DeleteDatabase().... Then you can recreate the database again.

Well problem is, now I still can't recreate the old database because the system thinks the name already exists.

Is there a way to get rid of the reminents of the old databse file the "does not exist"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to open master database via server explorer in Visual Studio (Add New Connection + Select master database) then add a New query, type Drop Database xxxx and execute it. You can also use Sql Server Management Studio.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...