Click here to Skip to main content
15,884,598 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
how to backup oracle database using c# application.
I trying examples but didnt worked. Like this one. I dont understand some of the lines. Please give me some example of codes . Please. and Thank you .

What I have tried:

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();

}
Posted
Updated 23-Dec-18 2:47am

1 solution

See answers here: c# - Backup of Oracle database from .net through code - Stack Overflow[^]
It also helps to run your application, or Visual Studio, as administrator.
 
Share this answer
 
v2
Comments
Afyfy 23-Dec-18 9:04am    
I Did but didnt worked
I need an exmeple using c# application
thanks mr Rick
RickZeeland 23-Dec-18 10:46am    
What Oracle version are you using ?
Can you find the exp tool in the Oracle bin directory ?
Afyfy 24-Dec-18 3:44am    
i have oracle 10g entreprise edition
Usually : i do ==> cmd.exe ==> write --- exp user/password file=d:/filebackup.dmp full=y --- and exit .ok
but i need to do it using c# application
thank you
RickZeeland 24-Dec-18 6:09am    
I thought maybe the ORACLE_HOME environment variable was not set, but as you can call exp normally this is apparently not the case. To be sure however I would place a breakpoint after the line psi.FileName = Path.Combine(oracleHome, "bin", "exp");
and see what the value of psi.FileName is.
Afyfy 25-Dec-18 2:36am    
the problem in the code is "Path" ....
i dont know what is the solution .

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