开发者

Backup a database using c#, the bak file gets bigger and bigger, how do I stop it from growing?

开发者 https://www.devze.com 2023-02-07 00:38 出处:网络
So the scenario is that It seems to append to the bak file when creatin开发者_C百科g it, is it possible to stop it from doing that and just backup the current version?

So the scenario is that It seems to append to the bak file when creatin开发者_C百科g it, is it possible to stop it from doing that and just backup the current version?

here is my code

Server backFromServer = new Server(@"server ip add");
backFromServer.ConnectionContext.LoginSecure = false;
backFromServer.ConnectionContext.Login = "uname";
backFromServer.ConnectionContext.Password = "psd";
Database backFromDb = new Database();
backFromDb = backFromServer.Databases["dbname"];

Backup bkpDatabase = new Backup();
bkpDatabase.Action = BackupActionType.Database;
bkpDatabase.Database = backFromDb.Name;
bkpDatabase.Incremental = false;
bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;                

BackupDeviceItem bkpDevice = new BackupDeviceItem(@"D:\backupfolder\backup.bak",
                                                  DeviceType.File);

bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackup(backFromServer);


Set Backup.Initialize to true:

"If True, the backup specified becomes the first backup set on the media, overwriting any existing backup sets on the media. "

0

精彩评论

暂无评论...
验证码 换一张
取 消