Can I commit changes to actual database while debugging C# in Visual Studio? Can I commit changes to actual database while debugging C# in Visual Studio? database database

Can I commit changes to actual database while debugging C# in Visual Studio?


Select the databases in Solution Explorer and change the "Copy to Output Directory" to "Copy if newer". Later, when you finally get the final version, copy paste the databases in debug folder to your source folders


The problem with 'Copy if newer' is that when you make changes to any part of the structure of the database, that change is to the version in your Project directory and not to the version you are building on in the Debug directory.

Also, when you try a non-debug run you are not using the copy you have been chaging in the debug location.

I normally use a Postgresql, but as this is a new computer and I discovered MS do this Lite version, decided to give it a try. I have a lot of data which is historic that I want in the table, then some manual manipulation with a bit of SQL, Then I can carry on creating the actual functionality of the database.

You can not just copy the altered version into the project directory, because there is a log file and no one seems to know what is in there but Microsoft desperately need that to match your database file in some way. (I am guessing you already tried that too).

I didn't want to have to start from scratch every time I ran it, and just like you I found no solutions. So in a desperate move I copied the version in Debug to a tmp directory. Then deleted the version in the project solution explorer.

Then I dragged and dropped the version in tmp into solution explorer. (Everything in it is structurally the same as the original, except as stated below)

That did it, it recreated that Log file. Now my debug sessions start with a ready loaded data.

Words of warning.1) Changing the database structure.In your solution explorer, the the Linq to SQL DBML file, if you have changed some structural part of the database in code (which is where I tend to do it), right click on the DBML file and go into design view. Then drag into the design any new tables or views that you have added.

2) Because having to delete and drag in the database feels a bit dodgy, write yourself a function that runs on Form_Open when in debug mode that copies your database file such as

\MyDatabaseBackup\myDatabase_date_time.mdb

Remembering that if you do go back to a previous version at any time you need to rename it myDatabase.mdb


Copy database to some proper location and change the connection string in config file to point to that only, it is only a suggestion as not sure what type of app. it is.