Linq To Sql update mdf file using clickonce - c#

I have a application that use Linq2sql and have a database (mdf file). I using clickonce to release the application. I need to make changes in the database structure, How can i do this and update the mdf files using clickonce without losing the data at the files?

If you place your mdf in the data directory then you can have access to that previous-version-mdf-file when the newly installed version is run for the first time, since old data files are accessible in a PRE directory.
So at that moment you can copy the data from the old mdf to the new mdf.
To give you the full picture, are data files are renewed when a new installation is done. Its up to you to copy any old data.
Link which explain the first run of a clickonce installation:
How do I detect the first time a ClickOnce-deployed application has been run?
Link which mentions the PRE data directory to access files from the previous version.
clickonce - does writing/reading to the Data Directory required Admin rights?

Related

WPF Desktop app how to include a sqlite DB

I am developing a WPF desktop application that uses a SQLite DB and this is in my App_data folder which is fine while a run it in debug but how do i include a DB file when i build my application and run it on another computer? do i need to build an installer for my app to create a copy of the DB in a location on the users machine that has read/write access?
Thanks
You could create the database in your initialization routines if the database doesn't exist. You can include the location and other settings in your app config. Check this link out: Create SQLLite Database and Table
It sounds like you want to have your SQLite database included in your project output including all the records that were added (i.e. you do NOT want to deploy an empty copy of the database, but rather the same data that you were working with during development).
To accomplish this, add the SQLite database to your project and set the build action to "copy to output location". In your config file, you can then set up the connection string to look for the file in the application directory.
Now, every time you build the project, a fresh copy of the database will be placed in the output directory.

Data lost from .mdf file as I exit application

Recently I work on SQL Server 2008 R2 database. I create database and attach .mdf file of same database in my application with some default data in it . Run application default data coming properly. Now I insert, update some data in my application and its works fine. But as I exit application and again run application lastly added and updated data get lost but default data coming proper as earlier. Please help. Why new
As mention by #Henk , #Microtechie , I scan my project folder and found there are 3 copies of .mdf file are there, 1st in project folder where code project([ProjectFolder ]) resides 2nd in [ProjectFolder]/bin/debug folder and 3rd in [ProjectFolder]/bin/release folder and suddenly solution to my que trigger in my mind. Problem not in multiple .mdf files in project folder, as I every time ‘Clean’ and ‘Build’ my solution new copy of .mdf file from [ProjectFolder] get copied into [ProjectFolder]/bin/debug folder, result in override of last .mdf file in same folder. Hence every time I build and run application only default data coming and last added and updated data get lost.
Thanku all for your replies and precise answer..!
What kind of object do you load your .mdf file data into? It is likely that you need to save the changes in that object before closing the application.

database connectivity in c#

I am working on c# windows project.I am using Microsoft Access database with OleDbConnection connection.My database "email.mdb" is in My document directory and my "email_db.udl" is in "D: drive".This is running well on my computer.But whenever i am making an exe installer file for installment on other Pc this is not working.I am placing "mdb" and "udl" file is in same directory as they are on my PC.I am supposing this ('udl' file) is not connected with my database.
How will i resolve this problem for installation on any windows pc.
Thanks
You can put the database files in your project's directory (where sln file is) and access them through their bare filenames (without D:...., only filename).
In case of the installation you have to set the installer to put it in the installation folder (where the exe file is)
This is a good way to carry everything in one folder and be organized.
Probably here you have a problem because the "My Document" directory has a different path in every PC.

how to handle temporary files/folders of VS setup project?

Still learning create MSI installer with VS 2008 for our C# application. We have some batch files to create database and tables, after installation we want to delete it because there are sensitive information on them (username, password, ...). My questions are like those:
where should I put those temporary folders/files? (doesn't matter?)
how to delete them after installation? or how to call batch file from installer? I was able to add a custome action to modify app.config file but call batch file should be a different way. (simpler than having a installer class?)
how to guarantee those files will be deleted even something wrong during the installation?
thanks,
Instead of a batch file, which anyone can open and read, consider compiling the sensitive information and commands into an .exe. If you store information in a file on someone's PC, you cannot guarantee they will not copy and retain it.
Ideally, temporary folders and files get installed in the windows temp directory, but you can also install them in your application directory.
You can't guarantee the install will complete or files will get deleted, but you can do the delete (or whatever) as early as possible so they can't install without that deletion, or you can have your app or some other process complete the deletion after the install.

Validate Download process

"Idea to update the new version of application on client machine"
I have read binary data from DB server using WCF, create a zip file with contents, extract the files and update our application bin folder.
I want to validate the process like if everything is fine then update bin or rollback old file.
Can anybody give me idea to validate this process?
Do we have any check sum idea..
Well if you use SharpZipLib to inflate the zip file, there is a TestArchive method on the ZipFile object that will do an integrity check of the archive, and tell you if it's valid.
Otherwise, you can use MD5 to make a checksum on the remote file, and compare it to the downloaded file to see if the content is the same.
Store on the server/web the most recent version of the project that is online. eg: in a version.txt the value "2.1.0", or query the database if you have access too.
Your application running on clients, will periodically read the contents of the version.txt file, then compared against the inbuilt(self) version number.
If a patch or minor release is detected eg 2.1.123, spins out a second app(updater.exe) that will quietly
do the upgrade,
it shall download the updated(preferred zipped) project from server/web.
Stop any running instances.
Unzipping the content.
Backup existing files(rename)
copy/install the new version of the project,
Start the application (when the app is restarted successfully it will delete its own backup file).
if a major release is detected eg: 3.0.0
notifies the user there is a major upgrade
if user accepts, download the installer
runs a full installer update
Does this help?

Categories

Resources