Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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!
C#
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);




    }


[Edit]Code block added[/Edit]
Posted
Updated 15-Nov-12 5:46am
v2

1 solution

Try this, the code below is commented

C#
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 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
 
Share this answer
 
Comments
Nelek 25-Nov-12 14:04pm    
OP's comment to you moved from non-solution below
Hi, thanks for your reply but i get this error:
Error 7 No overload for method 'Combine' takes '3' arguments
on this line:
psi.FileName = Path.Combine(oracleHome, "bin", "exp")
Mahesh_Bhosale 8-May-13 7:15am    
try in vs2010

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900