Hello. Created a console application. Using code first. Copied from data source database:

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\ConsoleApplication1\ConsoleApplication1\MyDb.mdf;Integrated Security=True 

Created models, made migrations. I decided to find how to make the path in the line universal. What would the project was not tied to a particular place. I found such an option, or rather just in windows forms, added a grid to a form, and started adding a date set to it, and he generated this line, and I copied it from there:

 <add name="MyConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/> 

I do the migration, I update the database, but it was not there. With such a connection string, the table is not updated. What am I doing not so please tell me, already broke my whole head with this connection string.

  • This |DataDirectory|\MyDb.mdf indicates which database? What specific file? - tym32167
  • @ tym32167 On the one that lies in this project. - Andrei
  • Are you sure about this? Maybe you update the database in the Bin / Debug folder, and check for updates in the database in the project? - tym32167
  • one
    That doesn't tell me anything. Look for what specific database you are connecting to, since there is a suspicion that you are changing one database and waiting for changes in another. I have already seen this, this often happens here. - tym32167
  • one
    The necessary base is a broad concept. If your current universal string does not indicate where you want, change the connection string, specify the full path to the database file. Although, from my point of view, the required database is just in bin / debug, and among the source code there is nothing to do at all with the base - tym32167

0