Click here to Skip to main content
12,509,612 members (52,888 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# database
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);

 

 
    }

[Edit]Code block added[/Edit]
Posted 15-Nov-12 5:45am
Updated 15-Nov-12 5:46am
ProgramFOX187.6K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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 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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160929.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100