Roge
Roge

Reputation: 3522

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 ?

Upvotes: 0

Views: 320

Answers (2)

priyank
priyank

Reputation: 11

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.

Upvotes: 1

gideon
gideon

Reputation: 19465

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.

Upvotes: 1

Related Questions