Data disapears when table structure is altered?

kbutchm

Member
Joined
May 12, 2011
Messages
10
Programming Experience
1-3
Hi,

When I install a SQL Server Express database on a computer and enter data, everything works fine.
But if I alter the the tables in the database an install a newer version of the database, the data in the database is erased as if I was a brand new one.
Is this normal, because the database schema changes?
the 'Copy to output Directory' is set to "Copy if newer"!?

If I wanted to update the application with more tables, how can I do it without losing the data already there?
Thanks in advance
 
How are you 'altering the tables'? and what is the process 'install a newer version of the database'?
 
I am altering the tables by adding new tables to the database.
I am installing a newer version using VS2010 and deploying it by Publishing it.
If the database schema doesn't change the data is OK, but if the schema changes the data gets erased!!
 
This may be the problem, which I'm dealing with myself. When you create a new connection string or a new data source, you get the message "The connection you selected uses a local data file that is not in the current project. Would you like to copy the file to your project and modify the connection?"

If you say yes, your database is copied into the bin/Debug directory. As you develop your program, all your database queries and updates are going to that copy in the bin/Debug directory. However, when you change the schema, you're doing it to the original database, the one that it did not copy into the bin/Debug. And when you're done making your schema changes, the newly modified database (which has none of the data you entered during development) is again copied to the bin/Debug directory, overwriting the database file you had been working on.

I tried changing the Copy if Newer option, and I forget exactly why, but it didn't work. So I answer no to that question about moving the database.
 
When database Data File is changed both at client and in update the old client file is copied to a 'pre' subfolder of DataDirectory. ApplicationDeployment Class (System.Deployment.Application) can be used for on-demand updates where you perform additional steps to copy previous client data to the new version.
 
Back
Top