简体   繁体   中英

C# Express Edition + SQL Server 2008 R2 Express; Database file being recreated on run

I created a standard C# console application in 2010 Express, used the wizards to create a simple sql express db file which gets placed in the project dir, used the wizards to generate an entity data model based on the newly created db, wrote a few lines to test out entity.

Problem is each time I run the application it recreates the DB file in whatever dir the exe is in overwriting itself everytime and completly ignoring the original db file that sits in the project dir.

Does anyone know what I am missing here ?

Not entirely sure about this but try it out.

  1. Make sure your connection string points to the database file in the project directory.
  2. Select the file in Visual Studio and Choose 'Copy to Output Directory' ->> Do Not Copy.

Hope it works.

you must be using some way to find that file or some path parameter within the database connection that points to the database file. Now either you can have that parameter be generated by code or make the directory specific and make the database file copy at a specific location from the original location so that the only that particular database is accessed using the application. For doing that you can add another key in the application config file or at some other place so that the database your application is accessing is in the project directory itself at all times.

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