hi, freinds, need code to make an backup and restore database file
can you help me , thank's for all of you
Printable View
hi, freinds, need code to make an backup and restore database file
can you help me , thank's for all of you
FK
That is a rather open-ended request.
What code do you have so far?
Have you done a Search?
Spoo
What is required is that the database is saved as a backup when you close the program where I am when I tried it through (filcopy) always getting an error message (access denied) which I understand that the file is open
FK
You say --- "the file is open"
In my mind, a backup is a separate copy of the database,
preferably on a different drive or better yet, on a different machine.
So, why would the backup copy ever be open?
Do you really mean backup or
do you mean just a simple save to the original DBF?
EDIT:
BTW, I am not familiar with FileCopy.
And, as I asked earlier (but you didn't reply to), have you searched
for other threads in this Forum?
Spoo
Why don't you try to close the connection/dataenvironment before trying to copy the database...?
really thank you and I will try to explain to topic
I used the database through dataControl so when finished work and I try to copy backup from the file on drive d, I get an error message permission denied , I has concluded that this means that the file is open so I try to make the program closes the database file so that it can save a copy reserve but I don't know how to close this file
may be I explain the problem
You can do the following before copying:
Code:'If you are using a dbgrid(s) then:
Set DBGrid1.DataSource = Nothing
'If your using a data1(s) then:
Data1.Recordset.Close
Data1.RecordSource = ""
Data1.DatabaseName = ""
Data1.Refresh
Dearest ST.
sorry for late , it is due to some healthy problems,
I tried your code, but not work
kindly try another idea
thanks
yours
It should be working, i have tested here and copied the db, i think something you missed:
How many forms do you have with datacontrol/dbgrid/ado control/or any other control that uses db?
Make sure dataenvironment/declared recordsets&connections closed...then try again...
or just upload your project...
perhaps we should find out what kind of database we're dealing with here... if we're talking about SQL Server (Express or otherwise)... then a filecopy isn't going to work...
@fkwinna... you're last post is indicitive of the many things that's wrong with programming today. You don't walk into the Dr.'s office and say "it hurts" and expect him to fix it do you? Usually you explain "I tripped and fell, busted my arm" ... so simply saying "it doesn't work" doesn't tell us anything, jsut that it's broken. OK... so what happened? Did you get an error? What was it? did your arms fall off? Did you get toast when you asked for OJ? Did the wheels fall off your car?
Unless you can provide a CLEAR explanation of what is happening (or not)... then all I can offer is to suggest you remove the eels from your hover craft.
-tg
Dearest all of you
thank you very much for your help,
finally I get an Idea to resolve this problems,
1-when finish his work the user must make an copy from the database file as backup on another folder and another driver within a seprate application specialy for make the backup&restore file
2-that when the user begin the work before take any action and before openinig any table from the database file , and within the main application ,can make a backup file within the next code
''
Private Sub file10_Click()
Set rs = Nothing
Set cn = Nothing
MsgBox "DataBase File Closed And Ready To Create Back File"
Const attr_directory = 16
If Dir$("d:\Backup", attr_directory) <> "" Then
Else
MkDir ("d:\Backup")
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'rs.Close '
'db1.Close '
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim rrr As Integer
rrr = Weekday(Date)
If rrr = 1 Then w = "sunday"
If rrr = 2 Then w = "monday"
If rrr = 3 Then w = "ÇáËáÇËÇÁ"
If rrr = 4 Then w = "ÇáÃÑÈÚÇÁ"
If rrr = 5 Then w = "ÇáÎãíÓ"
If rrr = 6 Then w = "ÇáÌãÚÉ"
If rrr = 7 Then w = "satrday"
''''''''''''''''''''''''''''''''''''''''''''''''''
Calendar = vbCalGreg
DD = Format(Date, "yyyy-mm-dd")
aa = Format(DD, "(yyyy-mm-dd)") & Format(Time, "(hh-mm-ss)")
'aa=(date) & (time)
FileCopy App.Path & "\" & "inventory control1.mdb", "d:\Backup\inventory control1" & aa & w & ".mdb"
MsgBox ("backup completed on D"), 64
if any one have an new idea ,it is wellcome
sorry forgot to tell you that we must put the followin code in the main form
private sub form_load()
If cn.State = 1 Then cn.Close
If rs.State = 1 Then rs.Close
cn.Open "Provider = Microsoft.Jet.Oledb.4.0 ; Data Source = " & App.Path & "/inventory control1.mdb"
rs.CursorLocation = adUseClient
rs.Open "Select * from stocks", cn, adOpenDynamic, adLockOptimistic
MsgBox "DataBase Opened and Connected" & vbCrLf & "Table Opened"
end sub
and in the declaration
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset