1

I have a winforms project with a mssql database that stores user created data, All created in Visual Studio C# 2010. I am able to publish the project and deploy with clickonce on my local machine. The application updates automatically and works great. when i install the newer version it drops all table data in the database. I currently don't have any data in the database that deploys when i publish, but would like to if needed in the future.

Is there a way to change this behavior in visual studio? if not how do i go about stopping the database from dropping all the users data on update?

I asked this question previously, However users thought it was non constructive. One user stated "this looks more like an issue with the setup that just overwrites the database and has nothing to do with C# or Visual Studio"

Can somebody possibly elaborate on what this user meant by SETUP?

I think this would be a very constructive question as this is a pretty important part of automatically updating a winforms application. I have searched but cannot seem to use the right words for this problem. If this isn't constructive or relevant to this site, Can somebody at least point me in the right direction?

  • `when i install the newer version it drops all table data in the database.` I've never heard of this problem. Perhaps you need to show how you're installing. Do you have code that deletes data? If so, remove it. :) – Bob Horn Dec 04 '12 at 03:00
  • I didnt write any code that pertains to install or update. No code that deletes data created by me. I install by clicking publish. Visual Studio Express is setup to install to IIS location. After VSE publishes, It opens a webpage on my local machine which it created. I click the install link. I update by simply clicking publish then opening the already installed application. It ask if i want to update. Click install. Program opens with new version but has dropped all data previously entered. – user1804465 Dec 04 '12 at 03:13
  • I suspect the issue you've got is that you ship your database as part of your deployment. So when you deploy, it overwrites everything that was there before - including the database. I don't have a solution for you; in my case the database is separate to the application and whilst I have connections to it, it's not part of the deployment package, only the code referencing it is. Ie db is on a separate server. – andrew Dec 04 '12 at 04:05

1 Answers1

1

I think the user previously was right. If I am understanding your problem correctly then it has more to do with versioning and deployment strategy than VS or C#.

You could build functionality into your app to check the version of the app on load and whether a database already exists and then make a decision on what to do from there.

A solution could be to deploy with SQL scripts that update the database based on what version you are deploying or if the database exists previously rather than simply overwrite it

possible answer

deployment strategy

another deployment strategy esp Strategy #3 - use re-runnable scripts

EDIT I think your problem has very little to do with whether you're deploying using debug or release

Community
  • 1
  • 1
kurasa
  • 5,205
  • 9
  • 38
  • 53
  • You are correct. it didn't help. I made some simple changes earlier and it didn't drop the tables. I just updated with a large code change that included new instances of table adapters that already existed (i.e no changes to database, just code.). Again it dropped all data. – user1804465 Dec 04 '12 at 20:54
  • I think you need to address your strategy. I don't think it will be as simple as changing a setting somewhere. If it is just the user settings that you are worried about keeping then maybe they could be kept in a separate file from the database and you could continue with your current strategy. However this strategy would give you very limited flexibility in the future. To implement a working solution is not as hard as you maybe thinking it is. Did you read the links I posted esp. re-runnable scripts? – kurasa Dec 05 '12 at 00:11