C#Windows应用程序中的数据库备份和还原 [英] Database Backup and restore in C# Windows Application

查看:71
本文介绍了C#Windows应用程序中的数据库备份和还原的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请有人可以帮助我吗?我想备份和还原C#Windows应用程序中的所有类型的数据库(MySQL,SQL Server,MS SQL,MS Access,Oracle和DB2).我可以成功进行备份和还原MySQL和SQL Server,请不要
适用于Oracle和DB2.请提供链接或源代码来帮助我.

在此先感谢.

Tristan

Hi All,

Please Can anyone help me ? I want to take backup and restore all types of database(MySQL, SQL Server, MS SQL, MS Access, Oracle and DB2) in C# Windows Application. I can successfully take backup and restore MySQL and SQL Server, don''t
for Oracle and DB2. Please help me by giving links or source code.

Thanks in Advance.

Tristan

推荐答案

这将适用于Oracle数据库:

This Would Work for Oracle database:

OledbCommand cmd=new OledbCommand ("backup database databasename to disk ='C:\databasename.bak'",con);
con.open();
cmd.ExecutenonQuery();
con.close();




除了 Ger Hayden 解决方案之外,您还必须
考虑超时,导致备份有时需要
太长了.

示例代码:

在您的Web.config中,您具有:
Hi,

In addition to Ger Hayden Solution, you must also
consider the Time out, cause backup sometimes take
too long.

Example code:

In your Web.config you have:
<add name="ClaimsORAConnection" connectionString="Provider=MSDAORA;Data Source=Your serverName;User ID=YourUserId;Password=YourPassword"/>




然后在您的代码后面:




and then in your code behind:

OleDbCommand ocmd = new OleDbCommand();

string strConn = ConfigurationManager.ConnectionStrings["ClaimsORAConnection"].ConnectionString.ToString();
OleDbConnection aConn = new OleDbConnection((strConn + ";Connection Timeout=300; pooling=''true'';Max Pool Size=300"));

string strQry = "backup database databasename to disk =''C:\databasename.bak''"
try
{
   ocmd.CommandTimeout = 300;
   ocmd = new System.Data.OleDb.OleDbCommand(strQry, aConn);
   ocmd.ExecuteNonQuery();
}
catch (Exception)
{
    return "Backup process failed...";
}
finally
{
   ocmd.Dispose();
   aConn.Close();
}



连接超时应该与命令超时保持公平,否则
进程捕获超时.

您可以将超时时间"调整为300或更多,
视处理时间而定


请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.


希望对您有所帮助.


问候,

代数



The Connection Timeout should be fair with Command Timeout otherwise
process catch Timeout.

You may adjust the Time out duration from 300 or more,
depending in time of process


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Hope this could help.


Regards,

Algem


尝试使用我在此处发布的类 http://g4ac.co.za /RjwyM [ ^ ]
try using the class I posted here http://g4ac.co.za/RjwyM[^]


这篇关于C#Windows应用程序中的数据库备份和还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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