开发者

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.

Pr开发者_JAVA百科oblem 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜