简体   繁体   中英

Sql Query for taking backup in MSAccess 2007?

Is there any sql query for MS-Access database to take backup directly from c#Application? if not,then how to do it from c#Application?

i am developing a C#.net application with access as back-end.

now what i want is, a sql query so that when i execute it i so should get a backup file in a folder.

i have tried it in sql server using query "BACKUP DATABASE AdventureWorks TO DISK = 'C:\\AdventureWorks.BAK';" But i don't know how to do it in Ms MS-Access? please help.

Microsoft Access is a single file database system. You don't have any built in function in JET-SQL to create a backup of the database itself. As others have said you simple copy the database in another location. If the size of the database is big (however Access has a 2gb limits) then you could ZIP it before storing away the zipped file.

I have used this library DotNetZip at CodePlex (I am not involved in any way with the author)

void Main()
{
    CopyToZip(@"D:\temp\temp.accdb", @"D:\temp\temp.zip");
}
private static void CopyToZip(string source, string dest)
{
     using (ZipFile zip = new ZipFile(dest))
     {
         ZipEntry e = zip.UpdateFile(source, string.Empty);
         e.Comment = "Database archived in date: " + DateTime.Today.ToShortDateString();
         zip.Save();
     }
}

An advice. Remember to close any connection before executing the backup. MS-Access has not a bullet-proof log and recovery system like its big cousin, and if any thread is writing to the database while you take a backup, the result is probably a corrupted file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM