Back up database.sdf

A

A_PK

Could someone guide me how to write a code to back up database.sdf ?

the back up feature must allow the user to select the the source path, and
the destination path.
Also must include the following two options.

option 1 - Regular - manually backup...
option 2 - set a timer, and run a scheduled backup...

my working environemtn is pocket pc 2003, vb.net.

thank you veyr much
Pierce
 
G

Guest

I'm not sure what you're asking - it's just a file. Copy it using the
System.IO.File methods.

-Chris
 
A

Alex Feinman [MVP]

Just don't forget to close connection first. Although I prefer to use
SqlCeEngine.CompactDatabase - it shrinks a copy, often significantly. Even
better, compact database first, and then copy it to theh backup media
 
A

A_PK

could you foward some sample coding for me ?

Alex Feinman said:
Just don't forget to close connection first. Although I prefer to use
SqlCeEngine.CompactDatabase - it shrinks a copy, often significantly. Even
better, compact database first, and then copy it to theh backup media
 
M

Milsnips

Sub CompactDatabase
Dim f As IO.File
Try
eng = New SqlCeEngine
eng.LocalConnectionString = DATABASE_CONN
If f.Exists("\My Documents\Compact.sdf") Then f.Delete("\My
Documents\Compact.sdf")
Application.DoEvents()
eng.Compact(DATABASE_COMPACTED)
'rename the compacted file to ordersDB.sdf
If f.Exists("\My Documents\ordersDB.sdf") Then
f.Delete("\My Documents\ordersDB.sdf")
f.Copy("\My Documents\compact.sdf", "\My
Documents\ordersDB.sdf")
f.Delete("\My Documents\Compact.sdf")
End If
If Not hideMsg Then MsgBox("Database has been compacted.",
MsgBoxStyle.Information, "Compact Database")
Catch ex As SqlCeException
'MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Compact Error")
Catch ioEX As IO.IOException
'MsgBox(ioEX.Message, MsgBoxStyle.Exclamation, "I/O Error")
Finally
f = Nothing
eng = Nothing
End Try
End Sub

regards,
Paul.
 
A

A_PK

hi Milsnips...

what is the eng.Compact(DATABASE_COMPACTED) ?

i mean the DATABASE_COMPACTED ?

regards
 
A

A_PK

hi...some questions...

I understand that we need to have Database_CONN to get the date source...
I understand that we need to have Database_COMPACTED to compact our data to
the particular folder

Just a bit confused, why we need to rename our compacted data (Compact.sdf)
to ordersdb.sdf ?
Since it is just copy and paste, cant we just keep the compact.sdf, and skip
the steps of renaming to ordersdb.sdf ?

If we just compact the databased to compact.sdf, but we do not rename it to
ordersdb.sdf. Is it ok ? Just simply treat compact.sdf as a backup database.
 
A

Alex Feinman [MVP]

Compacting database is a good practice. You need to do it once in a while to
avoid it growing uncontrollably. Typically it is done the way the other
poster has described it. In your case, you might want to make a copy of
compact.sdf as OrdersDB.sdf to get a working copy *and* a backup
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top