Results 1 to 16 of 16

Thread: Backup of SQl

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Backup of SQl

    Hi

    How we can take a Backup of SQL Express Database using Visual Basic as Front-End . I want to give user an option to take Backup.

    Thanks

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Backup of SQl

    Can you use filecopy?

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: Backup of SQl

    Quote Originally Posted by SamOscarBrown View Post
    Can you use filecopy?
    On an SQL Express Database?
    I'd rather do an SQL-Dump into a Textfile (csv) per Table and be done with it.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Backup of SQl

    Probably......that is why I said "Can?" "-) Just downloaded SQL Express yesterday, and plan to start learning to use it with VB6....didn't realize the database was like ORACLE's, where a dump IS the best option. Lo Siento.

  5. #5
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Backup of SQl

    Hi,

    Have a look at a previous post of mine on another forum. This is in .NET but I am sure you can accommodate this example in VB6:-

    http://www.vb dot net forums .com/mysql/53335-code-backup-restore.html

    NB. Remove the spaces in the link since this forum does not allow linking to the forum I am trying to direct you to??????

    Cheers,

    Ian
    Last edited by IanRyder; Feb 21st, 2013 at 11:07 AM. Reason: Link Not Accepted??

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Backup of SQl

    Thread moved to the 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)


    Quote Originally Posted by IanRyder View Post
    NB. Remove the spaces in the link since this forum does not allow linking to the forum I am trying to direct you to??????
    A site with a very similar name (without the S) spammed us quite a bit at some point, so their name was added to our filtering system - which unfortunately causes this one to be partially masked too.

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Backup of SQl

    WHy not just write a Stored Proc to backup your database (tons of references on the web on how to do this), and then call the procedure from you VB application?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Backup of SQl

    Thanks si_the_geek - that explains a lot.

    Cheers,

    Ian

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

    Re: Backup of SQl

    Quote Originally Posted by SamOscarBrown View Post
    Can you use filecopy?
    Eww! No... would not recommend that... 1) takes up a lot of space, 2) you would have to copy both the mdf and the ldf files... see #1, 3) The files are live and you run the risk of corrupting the database... in the amount of time it takes to copy the mdf, the ldf will (may) be getting updated... now the two are out of sync.


    Quote Originally Posted by Zvoni View Post
    On an SQL Express Database?
    I'd rather do an SQL-Dump into a Textfile (csv) per Table and be done with it.
    That's almost worse than doing a filecopy. I know it's the way MySQL works, but I don't like it and it takes an exorbitant amount of time to run, and don't forget point 1 & 3 above...



    Quote Originally Posted by SeanGrebey View Post
    WHy not just write a Stored Proc to backup your database (tons of references on the web on how to do this), and then call the procedure from you VB application?
    That's the sanest thing I've heard... although I wouldn't do it in a stored proc... just issue the commands directly from the app... it's easiest and fasted way to ensure that the backup is complete and proper.

    -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??? *

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Re: Backup of SQl

    Hi

    Can u tell me some links

    Thanks

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Backup of SQl

    This is the T-SQL command used in MS SQL to backup a database

    Code:
    BACKUP DATABASE DocTest TO DISK = 'D:\some folder\DocTest_20130223.bak'
    Note - while this is fine to execute against a MS SQL Express type of database - DO NOT DO this against a production SQL SERVER running a NON-EXPRESS version. If that SERVER is already running maintenance plans for doing backup you should use the MAINTENANCE PLAN to run a ONE-OFF backup.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: Backup of SQl

    You could shell out to a command line to export the required tables, using sqlcmd or bcp -
    http://stackoverflow.com/questions/4...r-using-sqlcmd

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Backup of SQl

    Why are we talking about EXPORTING tables and making TEXT FILES here?

    MS SQL SERVER - a "multi" physical file database system (has both MDF and also LDF files - data and log portions) - should only EVER be backed up with the T-SQL BACKUP statement.

    This is executed just like any other SQL statement - using a regular command object.

    It can be done regardless of whether the client is on the same "workstation" as the DB itself - so it's network appropriate.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: Backup of SQl

    There's "ideal and proper", and then there's "what's good enough and what he wants to do for his own reasons"

  15. #15
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Backup of SQl

    It is really important to realize that TG mentioned a point that is key here. Let me elaborate...

    Changes made to a MS SQL SERVER database are first PLACED in the LOG file.

    The LOG does NOT ONLY contain UNCOMMITTED data - but also COMMITTED data that the lazy-time algorithms have not yet written back to the MDF file.

    That means when you run a select from the DATABASE there is a chance that data comes from both the MDF and LDF physical files.

    So a FILE COPY of the MDF or LDF is kind of unsafe - as you could imagine the timing of these physical disk copies will never correlate with the state of the MDF and LDF files as it is managed by the DATABASE ENGINE.

    The BACKUP command I show is a command handed off to the DATABASE ENGINE to do a CLEAN BACKUP of both the MDF and LDF files. These two files are placed into a single .BAK file - usually much, much smaller then the actual MDF and LDF files which have tons of allocated disk spaced used for database reasons. Single file that can be RESTORED and guaranteed to be a real copy of the DB at the POINT IN TIME it was run.

    If this is a single user SQL SERVER EXPRESS type of setup then a file copy could be done - but that's a bad habit to get into and doesn't actually, in my opinion, take less time or code to accomplish.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  16. #16
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Backup of SQl

    I agree with SzLamany and Techgnome.

    1. A backup is the correct mechanism provided by the DB engine. It's guarenteed to give the expected resut.
    2. It's trivial to carry out. Considerably easier than a filecopy, for example, which will require the additional actions to take the database off line before the OS will allow you access. And MUCH easier than trying to copy the data table by table (which will lose all your metadata).

    Trying to do a filecopy in these circumstances is like going to a restaurant and insisting they serve your soup in the collander you brought with you instead of the bowl they were happy to provide.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

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