运行update-database导致错误:“发生文件激活错误”

时间:2022-10-05 14:49:46

Basically I've created a class library project containing a data access repository for other projects to use. I've added the EF6 package and enabled migrations. My connection string in app.config looks the following:

基本上我已经创建了一个类库项目,其中包含一个数据访问存储库,供其他项目使用。我添加了EF6包并启用了迁移。 app.config中的我的连接字符串如下所示:

  <connectionStrings>
    <add name="Pbn" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Pbn.mdf;Initial Catalog=LM.DataAccess;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

(The project name is LM.DataAccess).

(项目名称为LM.DataAccess)。

When I run the update-database command I get the following error:

当我运行update-database命令时,我收到以下错误:

A file activation error occurred. The physical file name '\Pbn.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

发生文件激活错误。物理文件名'\ _PBn.mdf'可能不正确。诊断并更正其他错误,然后重试该操作。 CREATE DATABASE失败。无法创建列出的某些文件名。检查相关错误。

What could be the issue here?

这可能是什么问题?

1 个解决方案

#1


6  

This is the problem:

这就是问题:

AttachDbFilename=|DataDirectory|\Pbn.mdf

That's being interpreted as \Pbn.mdf, and it doesn't exist. This is because you aren't setting the |DataDirectory| value, so it's blank. See here on how to set it.

那被解释为\ Pbn.mdf,它不存在。这是因为您没有设置| DataDirectory |价值,所以它是空白的。请参阅此处了解如何设置它。

#1


6  

This is the problem:

这就是问题:

AttachDbFilename=|DataDirectory|\Pbn.mdf

That's being interpreted as \Pbn.mdf, and it doesn't exist. This is because you aren't setting the |DataDirectory| value, so it's blank. See here on how to set it.

那被解释为\ Pbn.mdf,它不存在。这是因为您没有设置| DataDirectory |价值,所以它是空白的。请参阅此处了解如何设置它。