|
-
Sep 7th, 2007, 04:04 AM
#1
Thread Starter
Hyperactive Member
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
-
Sep 7th, 2007, 05:49 AM
#2
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.
-
Sep 7th, 2007, 05:49 AM
#3
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
-
Sep 7th, 2007, 05:52 AM
#4
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 -.-
-
Sep 7th, 2007, 07:12 AM
#5
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.
-
Sep 7th, 2007, 06:15 PM
#6
Thread Starter
Hyperactive Member
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
-
Sep 7th, 2007, 06:22 PM
#7
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" + "'";
-
Sep 7th, 2007, 06:29 PM
#8
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.
-
Sep 7th, 2007, 09:35 PM
#9
Thread Starter
Hyperactive Member
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
-
Sep 7th, 2007, 11:09 PM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|