Results 1 to 10 of 10

Thread: back up .mdf and .ldf files?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    back up .mdf and .ldf files?

    hello!
    how to back up .mdf and .ldf files?

    i used File.Copy but always show the error msg, "the file is used by another process"

    tnx much
    *****************
    VB6,PHP,VS 2005

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: back up .mdf and .ldf files?

    That means the file you are trying to copy is in use. So basically until you end the process you can not involve it in any other operations.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: back up .mdf and .ldf files?

    If you want to backup an SQL Server database you either do it using Management Studio or else execute a T-SQL BACKUP DATABASE statement.

    http://search.msdn.microsoft.com/sea...=00&lang=en-us
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: back up .mdf and .ldf files?

    Jmc, I am not much of a database programmer, but doesn't the process need to be closed?? Sorry i am just a little confused and didn't interpret the question properly -.-

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

    Re: back up .mdf and .ldf files?

    MS SQL server allows hot backups while the database is in use - through the T-SQL BACKUP command or through doing a BACKUP with the Mgt Studio GUI.

    Actually this is the preferred method of doing a SQL backup - as it respects transactions that are in process and a restore from a backup done this way will properly retain the data that was committed as of the moment of 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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: back up .mdf and .ldf files?

    SqlConnection conn = new SqlConnection(cVar.conString);
    conn.Open();
    SqlCommand comm = conn.CreateCommand();
    comm.CommandText = "backup database DBName to disk = '" + Application.StartupPath + @"\Backup\DBname.MDF" + "'";
    comm.ExecuteNonQuery();


    this is working but .ldf does not included, i have to backup both
    .MDF and .LDF right?
    *****************
    VB6,PHP,VS 2005

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

    Re: back up .mdf and .ldf files?

    That doese backup the MDF and LDF all into one single .BAK file.

    You are naming the file poorly - do not use this:

    Backup\DBname.MDF" + "'";

    instead use this...

    Backup\DBname.Bak" + "'";

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

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

    Re: back up .mdf and .ldf files?

    Also - you should timestamp those filenames - as doing a backup into an existing .BAK file will keep growing that file - adding new "backup sets" to the .BAK file. That only confuses you later if you need to restore.

    btw - if a query window you can execute RESTORE FILELISTONLY on a .BAK file and see what's in it. The .MDF and .LDF parts of the .BAK and how many backup sets are in it.

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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: back up .mdf and .ldf files?

    sorry its my first time to back up in MS SQL 2005
    if "backup database" is for backup
    what is the command if i want to restore the .BAK

    do i need to reattached myDatabase?
    or extract the .BAK and then overwrite the old one?

    ynx for your help
    *****************
    VB6,PHP,VS 2005

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: back up .mdf and .ldf files?

    sorry for my question...
    i tried to open MS SQL Server Management Studio and
    tried the Restore Database and it works fine.

    i think i don't need to use the RESTORE DATABASE command

    thank you and God Bless.
    *****************
    VB6,PHP,VS 2005

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