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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With