sql server mdf 文件数据库附件

发布于 2024-09-18 20:26:37 字数 1181 浏览 8 评论 0原文

我很难让 Visual Studio 2010(我认为是终极版本)正确附加到我的数据库。它已从原来的位置移至 #MYAPP#/#MYAPP#.Web/App_Data/#MDF_FILE#.mdf。我在这台机器上运行了三个 SQL Server 实例。我尝试用新文件替换旧的 mdf 文件,但无法获得正确的连接字符串。

我真正想做的只是打开一个数据库实例并运行数据库创建脚本。然后我可以在 Silverlight 业务应用程序 (c#) 中通过我的 edmx(从模型生成数据库)生成一个数据库

现在,当我转到 VS 中的服务器资源管理器时,选择添加新连接,选择 MS SQL Server 数据库文件 (SqlClient) ),选择我的文件位置(app_data 目录),使用 Windows 身份验证,然后单击“测试连接”按钮,出现以下错误:

无法打开物理文件“”。操作系统错误 5:“5(访问被拒绝。)”。尝试附加到文件“”的自动命名数据库失败。存在同名数据库,或无法打开指定文件,或位于 UNC 共享上。

mdf 文件是通过

  • 在 SQL Server Management Studio 中连接到(本地)在同一计算机上创建的。
  • 获取新查询。
  • 从生成的 ddl 文件粘贴 SQL。
  • 添加创建数据库[NcrCarDatabase]; GO; 在粘贴的 SQL 和
  • 执行查询之前。

然后我

  • 在 Management Studio 中断开了与数据库的连接。
  • 关闭 Management Studio
  • 导航到该实例的 DATA 目录
  • 将 mdf 和 ldf 文件复制到我的应用程序的 app_data 文件夹中。

我现在尝试连接到 Visual Studio 内的同一文件。

我希望这能让我的问题更加清晰:)。

连接字符串是:

数据 Source=.\SQLEXPRESS;AttachDbFilename=C:\SourceCode\NcrCarDatabase\NcrCarDatabase.Web\App_Data\NcrCarDatabase.mdf;集成 安全性=True;连接超时=30;用户 实例=真

I'm having a bear of a time getting visual studio 2010 (ultimate I think) to properly attach to my database. It was moved from it's original spot to #MYAPP#/#MYAPP#.Web/App_Data/#MDF_FILE#.mdf. I have three instances of SQL Server running on this machine. I have tried to replace the old mdf file with my new one and cannot get the connectionstring right for it.

What I'm really trying to do is to just open a DB instance and run a DB create script. Then I can have a DB that was generated via my edmx (generate database from model) in Silverlight business application (c#)

Right now, when I go to Server Explorer in VS, choose add new connection, choose MS SQL Server Database File (SqlClient), choose my file location (app_data directory), use Windows authentication, and hit the Test Connection button, I get the following error:

Unable to open the physical file "". Operating system error 5: "5(Access Denied.)". An attempt to attach to an auto-named database for file"" failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

The mdf file was created on the same machine by

  • Connecting to (local) in SQL Server management studio.
  • Getting a new query.
  • Pasting in the SQL from the generated ddl file.
  • Adding CREATE DATABASE [NcrCarDatabase]; GO; before the pasted SQL and
  • Executing the query.

I then

  • Disconnected from the DB in Management Studio.
  • Closed Management Studio
  • Navigated to the DATA directory for that instance
  • Copied the mdf and ldf files to my application's app_data folder.

I am now trying to connect to the same file inside visual studio.

I hope that gives more clarity to my problems :).

Connection string is:

Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\SourceCode\NcrCarDatabase\NcrCarDatabase.Web\App_Data\NcrCarDatabase.mdf;Integrated
Security=True;Connect Timeout=30;User
Instance=True

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

给不了的爱 2024-09-25 20:26:40

为您的应用程序文件夹和 .mdf.ldf 文件提供完全控制安全性。单击包含 .mdf、.ldf 文件的文件夹,

  1. 转到属性
  2. ,单击安全性,
  3. 单击允许中的完全控制。

然后他们继续您的流程。

Give Security to Full control for your application Folder and .mdf, .ldf files. Write click on the folder which contains .mdf,.ldf files

  1. Go to property
  2. click security in that
  3. Click Full Control in allow.

and them proceed your process.

一场春暖 2024-09-25 20:26:39

访问被拒绝很可能意味着您在执行操作之前已经有一个活动实例打开了该文件 - 如果您有三个活动实例,则很可能其中之一就是罪魁祸首。

您可以尝试使用 Management Studio 连接到不同的实例,看看是否可以在那里找到基础。如果是,请将其与实例分离并从 Visual Studio 重试。或者,如果可能,请尝试关闭所有三个实例,然后从 Visual Studio 重试。如果有效,请一一重新启动实例以确定哪个实例正在尝试获取该文件。

我之前回答过一个类似的问题,可能会帮助

Access denied might well mean that you already have an active instance that has opened the file prior to you doing it - and if you have three active instances, it is likely one of them that is the culprit.

You can try to connect to the different instances with Management Studio and see if you can find the base there. If yes, the detach it from the instance and re-try from Visual Studio. Or, if possible, try to shut down all three instances and then re-try from Visual Studio. If that works, restart the instances one by one to determine which of them is trying to get the file.

I've previously answered a similar question that might help.

落花随流水 2024-09-25 20:26:39

您的 Sql 服务器服务在给定帐户下运行。您应该通过服务属性确定帐户,然后将该帐户的数据库文件安全访问权限更改为完全访问权限。

Your Sql server service runs under a given account. You should determine the account through the service properties then change the db file security access to full access for that account.

故人如初 2024-09-25 20:26:38

在我以管理员身份运行 Visual Studio 之前,我一直遇到“访问被拒绝”的情况。然后,我必须先将数据库与 MSSMS 分离,然后才能将其导入 Visual Studio。

I was getting "access denied" until I ran Visual Studio as an administrator. I then had to detach the database from MSSMS before I could get it into Visual Studio.

皇甫轩 2024-09-25 20:26:38

您提到您的 MDF 文件已被移动。移动后 MDF 是否正确连接到 SQL Express?请参阅:如何:将数据库文件附加到 SQL Server Express

You mentioned that your MDF file was moved. Was the MDF properly attached to SQL Express after the move? See: How to: Attach a Database File to SQL Server Express.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文