tags:

views:

41

answers:

2

Why are database records lost when I'm debugging the winforms application? When I start the debugging app, records are saved into the database, but when it is restarted, all of the database records are lost and the database tables are empty. How can I debug an application without losing the data?

+1  A: 

Are you sure the database is actually being updated? Have you checked with something other than the program you're debugging?

Is there perhaps a transaction that you are not committing?

Edit in reply to your comment

It sounds like maybe you need to change the properties of your database file in your Visual Studio solution - turn off "Copy to output folder".

Blorgbeard
my record saved to database when app is in running, this records saved in the database located in bin directory, and when vs restarted and rebuilded, new copy of my db replased to old db, how can i sade records in database to preventing lost records?
Sadegh
hi friend, i'm want save entered data to that database located in root of project, not that database which located in bin directory.
Sadegh
have'nt any solution or tips to resolve this?
Sadegh
+2  A: 

It sounds like you might be adding the records in a transaction and then not committing it. When you exit from the application (debugging session), the transaction is rolled back, and all your changes are lost.

Jonathan Leffler
how can i save records to database to preventing lost thats?
Sadegh
In pure SQL, you'd say 'COMMIT'. In your debugging session, I'm not sure exactly what you'd need to do. Maybe you should create a procedure that does commit that can be called when you are in the debugger. It might be helpful to know which DBMS you are using, too.
Jonathan Leffler
i'm using sql-server db to and linq for saving records. when i want to insert records to table, first i call InsertOnSubmit, then SubmitChhanges for saving. its wrong?
Sadegh