在 Visual Studio 中从 SQL Server Express 数据库获取数据库名称
我当前正在使用此连接字符串附加到我在 Visual Studio 中创建的数据库:
Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Database1.mdf;User Instance=true
我正在尝试使用 IIS 托管该站点,这样我就可以处理响应标头,但我遇到了此处描述的问题:实体框架代码优先的 SQL Server Express 连接字符串
I'我试图找到什么数据库名称指定但没有任何运气。我尝试了 Initial Catalog=Database1
但这给了我这个错误:
无法创建文件“D:\docs\Visual Studio” 2010\项目\QuickHomePage\QuickHomePage\App_Data\Database1.mdf' 因为它已经存在了。更改文件路径或文件名,然后 重试该操作。
创建数据库失败。列出一些文件名 无法创建。检查相关错误。
我只是想附加到Database1.mdf
。为什么尝试创建它时会出现错误?一条评论建议将 .mdf 文件附加到另一个数据库实例以查看其中的内容。
这需要运行 SQL Server Management studio 吗?每次我尝试连接到服务器类型数据库引擎和本地计算机时,都会出现连接错误。
I'm currently using this connection string to attach to my database that I created in Visual Studio:
Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Database1.mdf;User Instance=true
I'm trying to host the site with IIS so I can mess around with response headers but I'm getting the problem described here: SQL Server Express connection string for Entity Framework Code First
I'm trying to find what database name to specify but not having any luck. I tried Initial Catalog=Database1
but that gave me this error:
Cannot create file 'D:\docs\Visual Studio
2010\Projects\QuickHomePage\QuickHomePage\App_Data\Database1.mdf'
because it already exists. Change the file path or the file name, and
retry the operation.
CREATE DATABASE failed. Some file names listed
could not be created. Check related errors.
I'm just trying to attach to Database1.mdf
. Why is it giving errors about trying to create it? One comment suggested attaching the .mdf file to another database instance to see what's inside it.
Would that require running SQL Server Management studio? Every time I try to connect to Server Type Database Engine and the local machine it gives a connection error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据库名称是您将 .MDF 文件附加到 SQL Server (Express) 服务器实例时为其指定的名称。您需要发现的 MDF“内部”没有固定的数据库名称 - 这完全取决于您在服务器上如何称呼数据库。
因此,如果您像这样附加
Database1.mdf
:那么您的数据库名称是
CrazyDatabase
- 但这与原始 MDF 的文件名或其中的任何内容没有任何联系 -您也可以将其称为任何其他名称 - 无论您选择什么。在这种情况下,您的新连接字符串将是:
The database name is the name you give your .MDF file as you attach it to the SQL Server (Express) server instance. There is no fixed database name "inside" the MDF that you need to discover - it's totally up to you what you call your database on the server.
So if you attach your
Database1.mdf
like this:then your database name is
CrazyDatabase
- but that has no connection whatsoever to the original MDF's file name or any contents inside it - you could call it anything else, too - whatever you choose.In this case, your new connection string would be: