Results 1 to 12 of 12

Thread: [RESOLVED] backup&restore database files

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Resolved [RESOLVED] backup&restore database files

    hi, freinds, need code to make an backup and restore database file
    can you help me , thank's for all of you

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: backup&restore database files

    FK

    That is a rather open-ended request.

    What code do you have so far?
    Have you done a Search?

    Spoo

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Re: backup&restore database files

    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

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: backup&restore database files

    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

  5. #5
    Lively Member Stupidiot's Avatar
    Join Date
    Apr 2011
    Location
    India
    Posts
    95

    Re: backup&restore database files

    Why don't you try to close the connection/dataenvironment before trying to copy the database...?

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Re: backup&restore database files

    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

  7. #7
    Lively Member Stupidiot's Avatar
    Join Date
    Apr 2011
    Location
    India
    Posts
    95

    Re: backup&restore database files

    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

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Re: backup&restore database files

    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

  9. #9
    Lively Member Stupidiot's Avatar
    Join Date
    Apr 2011
    Location
    India
    Posts
    95

    Re: backup&restore database files

    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...

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: backup&restore database files

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Re: backup&restore database files

    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 = "&#199;&#225;&#203;&#225;&#199;&#203;&#199;&#193;"

    If rrr = 4 Then w = "&#199;&#225;&#195;&#209;&#200;&#218;&#199;&#193;"

    If rrr = 5 Then w = "&#199;&#225;&#206;&#227;&#237;&#211;"

    If rrr = 6 Then w = "&#199;&#225;&#204;&#227;&#218;&#201;"

    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

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    47

    Re: backup&restore database files

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width