Running update-database results in the error: "A file activation error occurred"

database entity-framework entity-framework-6 visual-studio

Question

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:

  <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).

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

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.

What could be the issue here?

1
5
11/12/2014 3:20:45 PM

Popular Answer

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.

7
5/23/2017 11:58:45 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow