简体   繁体   中英

using |DataDirectory| in connectionstring of multiproject solution

I have 2 projects in the solution - one class library with entities for database (using EF), one for Winforms.

Connection string is in app.config of the Winforms application, and it works correctly:

<add name="LibraryContext" 
     connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MyLibrary.mdf;Integrated Security=True; "
     providerName="System.Data.SqlClient"/>

But when I try to provide migrations, I get an error:

A file activation error occurred. The physical file name '\\MyLibrary.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.

When I provide full path in connection string, everything works fine. I assume the problem is in DataDirectory . The project with entities for database doesn't see it or maybe see it as own DataDirectory and not the one for startup project (Winforms).

Please, help me to provide correct relative path for database.

Try this hope this will works.

Go to Property of project check setting tab. If you contain more then one connection string then remove it. and add connection string which you have in app config.

Thanks.

Happy Coding :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM