数据库已经存在。使用 CreateDatabase() 选择不同的名称
我遇到了一个问题,同时学到了一些东西......
我从现有的服务器数据库创建了一个 DBML。
我想从 DBML 创建本地数据库(一个 .mdf 文件)。我使用 DataContext.CreateDatabase("C:\xxxx.mdf") 创建了数据库。
然后我决定删除它(手动,这显然是一件坏事),因为当我尝试使用相同名称重新创建数据库时(即使文件已删除),我收到错误数据库已存在。使用 CreateDatabase() 选择不同的名称
我尝试查看注册表,但没有运气...我尝试在整个硬盘驱动器中搜索该文件...没有运气。
经过谷歌搜索,我发现您删除了使用CreateDatabase()
和DeleteDatabase()
创建的数据库....然后您可以再次重新创建数据库。
问题是,现在我仍然无法重新创建旧数据库,因为系统认为该名称已经存在。
有没有办法摆脱旧数据库文件“不存在”的痕迹
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要通过
服务器资源管理器master数据库> 在 Visual Studio 中(添加新连接 + 选择
master
数据库),然后添加一个新查询
,输入Drop Database xxxx
并执行它。您还可以使用Sql Server Management Studio。
You need to open master database via
server explorer
in Visual Studio (Add New Connection + Selectmaster
database) then add aNew query
, typeDrop Database xxxx
and execute it. You can also useSql Server Management Studio.
解决方案(通过 此处) 是使用 SSEUtil 分离现有数据库:
A solution (via here) is to use SSEUtil to detach the existing db:
这是对 localDB 混乱的快速修复。只需连接到 SQL 管理中的 (localdb)\MSSQLLocalDB。工作室/视觉工作室。
然后删除违规者,选中“关闭现有连接”
Here's a quick fix for a localDB mess. Just connect to (localdb)\MSSQLLocalDB in SQL Mgmt. Studio/Visual Studio.
Then delete the offender, checking "Close existing connections"
我实际上也遇到了同样的问题。之前我删了
(剪切)mysqlserver2012中的数据库并将其复制到我的应用程序文件夹中。在制作应用程序后,我遇到了此错误,并通过删除连接字符串的
Initial Catalog
部分解决了该错误。您的最终连接字符串应如下所示:
Data Source=;AttachDbFileName=database path\databaseName.mdf;Integrated Security=True" + ";User Instance=True" + ";Context Connection =错误;
I also actually had this same problem. Previously, I deleted
(cut) the database in mysqlserver2012 and copied it to my application folder. After I made my app I got this error, and solved it by removing the
Initial Catalog
part of my Connection String.Your final connection string should look something like this:
Data Source=<your server name>;AttachDbFileName=database path\databaseName.mdf;Integrated Security=True" + ";User Instance=True" + ";Context Connection=False;