如何在c#.net windows应用程序中的sql server数据库备份期间显示进度条? [英] How to show progress bar during sql server database backup in c# .net windows application?

查看:213
本文介绍了如何在c#.net windows应用程序中的sql server数据库备份期间显示进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在创建用于创建sql server数据库备份的Windows应用程序。

它已经成功完成了但是我想在本地驱动器中创建数据库备份时显示进度条。



我的代码是: -

Hello,

I am creating windows application for create sql server database backup.
It''s have done successfully but i want to show progress bar during create database backup in local drive.

my code is:-

string dbName="abc";
SqlConnection con = new SqlConnection(cnString1);
string DestDir = @"C:\DatabaseBackup";
if (!System.IO.Directory.Exists(DestDir))
{
   System.IO.Directory.CreateDirectory(@"C:\DatabaseBackup");
}
try
{
   con.Open();
   SqlCommand cmd = new SqlCommand("BACKUP DATABASE " + dbName + " TO DISK='" + DestDir + "\\" + dbName + ".bak' WITH FORMAT", con);
   cmd.ExecuteNonQuery();

   con.Close();
   MessageBox.Show("Database Backup Created 'C:\\DatabaseBackup\' drive and folder ");



所以,

这段代码怎么可能呢?



谢谢。

Ankit Agarwal

软件工程师


So,
How could that possible in this code?

Thank You.
Ankit Agarwal
Software Engineer

推荐答案

不是这样,但正如我之前所建议的那样,使用SMO: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backuprestorebase.percentcomplete(v = sql.105).aspx [ ^ ],另请参阅: SMO事件处理示例 [ <小时ef =http://msdn.microsoft.com/en-us/library/ms162183(v=sql.105).aspx\"target =_ blanktitle =New Window> ^ ]
Not this way, but with SMO, as I suggested before: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backuprestorebase.percentcomplete(v=sql.105).aspx[^], see also: example of SMO event handling[^]


Hi Ankit,



好​​问题(5 +)

然而,答案很简单 - < b>否的。

目前无法获得备份过程的事件。

因此你无法获得进度条。



[想法]也许你可以四处走动(如果你可以估算备份数据库大小)对文件大小进行检查,然后在GUI上显示估算百分比。



使用Zoltán的MSDN链接最终可以获得一个事件,这是一些指示,但不是过程本身。



*如果你确实找到了一种神奇的方式来做这样的事情,请告诉我们,对吗?



干杯,

Edo
Hi Ankit,

Good question (5+)
However, the answer is simply - No.
Getting events of the backup process is, currently not possible.
so you can''t really get a progress bar for this.

[idea] Perhaps you might go around and (if you can estimate the backedup DB size) perform checks on the file size, and then show the estimation percentage on the GUI.

Using Zoltán''s MSDN link is good for getting an event at the end, which is some indication but not of the process itself.

* if you do find a miraculous way to perform such a thing, do let us know, will you?

Cheers,
Edo


这篇关于如何在c#.net windows应用程序中的sql server数据库备份期间显示进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆