Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > updating application
 

updating application

I am using click once deployment to distribute my application.  The problem I am having is everytime there is an update the contents on the database is removed.  How do I update my appliction and keep the contents in the database?
Thanks
Randy0128  Monday, October 05, 2009 3:21 PM
What kind of database are you using? Access, SQLServer Express, SQLCE?

Check out the threads referenced in my post in the following thread; I think they will be helpful to you.

http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/c8c55be6-be34-47cf-93fc-6cc0bf97f2cf

RobinDotNet

Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev
RobinDotNet  Monday, October 05, 2009 3:50 PM
I am using a .mdf database and SQLServerExpress.  I also just got the book on clickonce deployment and read the chapter on  how to keep data entered on the database.  It looks like I have to write some kind of code to merge the old data with the new data.  In the load event for the start up form I have the following code:

If

 

System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then

 

If System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun Then

 

Me.Migratedata()

 

End If

 

End If

I am having a hard time coming up with the code to merge the old file with the new.  I have several tables in my database.  Do I need to go thru each one a merge them?  Also, is there a sample code in vb showing how to set the connection strings and to merge the tables?  The code in the book is in c# and I am having a little bit of a problem translating to vb.
Thanks

Randy0128  Tuesday, October 06, 2009 9:40 PM
Is that Brian Noyes' book?

The check for IsNetworkDeployed checks to see if the application is running as a ClickOnce application rather than just from visual studio.

IsFirstRun checks to see if it's the app just got installed or updated.

This is definitely one way to handle that move from one database to another. Brian used table adapters just to show how you could connect to and transfer the data from one database to the other.

Is this a production application, or just something you're messing around with? The reason I ask is because I'm going to be blogging this in the next two weeks -- I've already written the code samples, I just have to write the article that goes with them.

You don't live anywhere in the SF Bay Area, do you? I'm speaking on this at the East Bay .NET User Group meeting on October 14th.

RobinDotNet
Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev
RobinDotNet  Tuesday, October 06, 2009 11:25 PM

Yes it is Brian Noyes book and this is a production application.  I would like to see if there are samples in vb that I could modify to work in my application.  I'm about 10 hrs from SF plus I think that everything would be over my head anyway.

Randy0128  Wednesday, October 07, 2009 1:06 AM
It wouldn't be over your head, but that's too far to go!

Can you tell me what the differences are between the two versions of the database?

RobinDotNet
Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev
RobinDotNet  Wednesday, October 07, 2009 7:33 AM
The code from Brian's book is available in VB. See if this does anything for you.

http://www.softinsight.com/clickoncebook/

RobinDotNet
Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev
RobinDotNet  Wednesday, October 07, 2009 7:35 AM
I found the code to migrate the tables and I tried just testing on one table.  I also put in some msgboxes to see thru each step.  I then changed the records in my Company info in my application.  I then made some change in table so that there would be pre folder made.  I then ran the application and it updated it.  It didn't pick up that the file prefile exists and didn't continue with the migration and it overwrote my existing records that I had added in my application.  I had to change things a little from his code because he used a .sdf type file and I'm using a .mdf type file?  Also he uses a 'SqlServerCe'  and I used 'SqlClient.SqlConnection'.  But I don't think that the code is getting to the part where the new connections are made.  Any Ideas what might be wrong here?  The Build Action property is set to Content and the copy to output directory is set to copy if newer in the properties for BuilderEstimatorDatabase.mdf.  Below is the code that I used.
Thanks

Imports

 

System.Windows.Forms

Imports

 

System.Deployment.Application

Imports

 

System.IO

Imports

 

BuildersEstimator_2.BuildersEstimatorDatabaseDataSetTableAdapters

Imports

 

System.Data.SqlClient.SqlConnection


Public

 

Sub New()

 

' This call is required by the Windows Form Designer.

InitializeComponent()

 

' Add any initialization after the InitializeComponent() call.

 

If ApplicationDeployment.IsNetworkDeployed Then

 

If ApplicationDeployment.CurrentDeployment.IsFirstRun Then

Migratedata()

 

End If

 

End If

 

End Sub

 

Private Sub Migratedata()

MsgBox(

"Checking if Data file to migrate")

 

Dim preFile As String = Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, ".\.pre\BuidlersEstimatorDatabase.mdf")

 

If Not File.Exists(preFile) Then

MsgBox(

"Nothing to migrate")

 

Return

 

' nothing to migrate

 

End If

 

' Get a connection to the old data in the \.pre folder

MsgBox(

"Migrating Data Files")

 

Dim oldDataConnectionString As String = "Data Source=|DataDirectory|\.pre\BuidlersEstimatorDatabase.mdf"

 

Dim oldConnection As New SqlClient.SqlConnection(oldDataConnectionString)

 

' Get a connection to the new data

 

Dim newDataConnectionString As String = "Data Source=|DataDirectory|\BuidlersEstimatorDatabase.mdf"

 

Dim newConnection As New SqlClient.SqlConnection(newDataConnectionString)

 

' Fill a dataset with the migration data

 

Dim oldData As New BuildersEstimatorDatabaseDataSet()

 

Dim oldAdapter As New CompanyInfoTableAdapter()

oldAdapter.Connection = oldConnection

oldAdapter.Fill(oldData.CompanyInfo)

 

' Create a table adapter for the new database and a compatible data set

 

Dim newAdapter As New CompanyInfoTableAdapter()

newAdapter.Connection = newConnection

 

Dim newData As New BuildersEstimatorDatabaseDataSet()

 

' Fill the new data set with default data

newAdapter.Fill(newData.CompanyInfo)

 

' Merge the old data into the new schema

 

' Assumes compatible schemas - this is the hard part for

 

' Real apps with significant schema changes

 

For Each row As DataRow In newData.CompanyInfo

row.Delete()

 

Next

newData.Merge(oldData)

newAdapter.Update(newData)

 

End Sub

Randy0128  Wednesday, October 07, 2009 1:31 PM
Do you think it could be because you spelled the name of the database wrong? Or is it supposed to be "buidlers" instead of "builders" ?

RobinDotNet
Click here to visit my ClickOnce blog!
Microsoft MVP, Client App Dev
RobinDotNet  22 hours 30 minutes ago
Thanks again I made a dumb spelling error.  I checked it over and over and didn't see it until I put in a msgbox to show the preFile string. 

Now it starts the migrate but I get an error.  I put in a msgbox after each line of code and it gets to the line 'oldAdapter.Fill(oldData.CompanyInfo)' when the error happens.  I then removed that line from then code and tried again and I got to 'newAdapter.Fill(newData.CompanyInfo)' when the error happened again.
Am I doing the connections right since I had to do a little different than the sample code because it used a .spf file and I am using a .mdf file.  Also I am only testing this with one table in my database until it works then I'll add the rest of the tables.  Is that ok?
Thanks
Randy0128  16 hours 26 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• ClickOnce Prerequisites not being checked
• Bug in "Detected Dependancies" does not update when you switch solution configurations
• Signing the Assembly Manifests
• Not deterministic problem with mage.exe return code 2
• Help Signing ClickOnce Manifest And Sharing Certificate
• Setup File Deployment Question
• support other languages
• Need to have my application launch at logon, replacing the explorer.exe shell
• ClickOnce: how to specify credentials for publishing?
• sign cat files using signtool with pfx