![]() 复制using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; private void btnBackup_Click(object sender,那种 EventArgs e) { btnBackup.Enabled = false; Thread tr = new Thread(new ThreadStart(doBackup)); tr.Priority = ThreadPriority.AboveNormal; tr.Start(); //Thread.Sleep(3000); } /// <summary> /// 备份数据库 /// </summary> public void doBackup() { pbDemo.Value = 0; pbDemo.Maximum = 100; pbDemo.Style = ProgressBarStyle.Blocks; //pbDemo.Step = 10; Server srv = new Server(@"(local)"); Backup backup = new Backup(); backup.Action = BackupActionType.Database; backup.Database = "btnet"; backup.Incremental = false; backup.Devices.Add(new BackupDeviceItem(@"C:\agronet09.bak", DeviceType.File)); backup.Initialize = true; backup.PercentCompleteNotification = 10; backup.PercentComplete += new PercentCompleteEventHandler(backup_PercentComplete); //backup.Checksum = true; backup.SqlBackup(srv); } public void backup_PercentComplete(object sender, Microsoft.SqlServer.Management.Smo.PercentCompleteEventArgs e) { this.Invoke(new displayProgress_delegate(displayProgress), e.Percent); //Application.DoEvents(); } public delegate void displayProgress_delegate(int progress); public void displayProgress(int progress) { this.lbProgress.Text = "已完成[" + progress.ToString() + " %]"; pbDemo.Value = progress; btnBackup.Enabled = (progress == 100); } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.  |