如何使用C#应用程序备份Oracle XE数据库 [英] How to backup oracle XE database using C# application
本文介绍了如何使用C#应用程序备份Oracle XE数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用c#应用程序备份oracle XE数据库.我一直在搜索和尝试从谷歌的例子,但没有奏效.像这个.我不明白其中的一些说法.请给我一些代码示例及其解释.请.非常感谢hhhhhhhh!
Hi, I want to know how to backup oracle XE database using c# application. I''ve been searching and trying examples from google but didnt worked. Like this one. I dont understand some of the lines. Please give me some example of codes and its explanation. Please. Thank you very muchhhhhhhh!
private void btnBackupDB_Click(object sender, EventArgs e)
{
DateTime Time = DateTime.Now;
int year = Time.Year;
int month = Time.Month;
int day = Time.Day;
int hour = Time.Hour;
int min = Time.Minute;
int second = Time.Second;
int millisecond = Time.Millisecond;
string path = "C:/gams_off/backup";
// path = path + day + "-" + month + "-" + year + "-" + hour + "-" + min + "-" + second + "-" + millisecond;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "C:/gams_off/bin/Debug/Backup/back_up.bat";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = string.Format("exp USERID=gams/gams FULL=y FILE=" + path + ".dmp CONSISTENT=y GRANTS=y BUFFER=100000 rows = Yes");
//psi.Arguments = string.Format("exp USERID=gams/gams@XE FILE=" + path + ".dmp TABLES=(t)");
psi.UseShellExecute = false;
Process process = Process.Start(psi);
process.WaitForExit();
process.Close();
MessageBox.Show("Database Backup Completed Successfully");
this.Close();
//string sql = "BACKUP DATABASE gams to disk='C:/orabackup'";
//db.show(sql);
}
添加了代码块[/编辑]
Code block added[/Edit]
推荐答案
尝试一下,下面的代码已被注释
Try this, the code below is commented
private void btnBackupDB_Click(object sender, EventArgs e)
{
//## Settings
//Path to store the oracle dump
string path = @"C:\backup";
string backupFileName = "mybackup.dmp";
//your ORACLE_HOME enviroment variable must be setted or you need to set the path here:
string oracleHome = Environment.GetEnvironmentVariable("ORACLE_HOME");
string oracleUser = "sys";
string oraclePassword = "abc";
string oracleSID = "xe";
//###
ProcessStartInfo psi = new ProcessStartInfo();
//Exp is the tool used to export data.
//this tool is inside
ORACLE_HOME \ bin目录 psi.FileName = Path.Combine(oracleHome," , exp"); psi.RedirectStandardInput = false ; psi.RedirectStandardOutput = true ; 字符串 dumpFile = Path.Combine(path,backupFileName); // 命令行为:exp user/password @ database file = backupname.dmp [OPTIONS ....] psi.Arguments = 字符串 .Format(oracleUser + " + oraclePassword + @" + oracleSID + FULL = y FILE =" + dumpFile); psi.UseShellExecute = false ; 处理过程= Process.Start(psi); process.WaitForExit(); process.Close(); MessageBox.Show(" ); 此 .Close(); }
ORACLE_HOME\bin directory psi.FileName = Path.Combine(oracleHome, "bin", "exp"); psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; string dumpFile = Path.Combine(path, backupFileName); //The command line is: exp user/password@database file=backupname.dmp [OPTIONS....] psi.Arguments = string.Format(oracleUser + "/" + oraclePassword + "@" + oracleSID + " FULL=y FILE=" + dumpFile); psi.UseShellExecute = false; Process process = Process.Start(psi); process.WaitForExit(); process.Close(); MessageBox.Show("Database Backup Completed Successfully"); this.Close(); }
埃德加·罗查·卡瓦略(Edgar Rocha Carvalho)
Edgar Rocha Carvalho
这篇关于如何使用C#应用程序备份Oracle XE数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文