Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi All,

How i can take backup of a specific table via expdp.exe utility using c# code?

What I have tried:

C#
string binary = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"ExportUtility", "expdp.exe");
            string arguments = @"UUU/PPP@orlc file=D:\testdmp\123.dmp tables=XYZ";
            ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo(binary, arguments);
            PSI.RedirectStandardInput = true;
            PSI.RedirectStandardOutput = true;
            PSI.RedirectStandardError = true;
            PSI.UseShellExecute = false;
            Process myProcess = System.Diagnostics.Process.Start(PSI);


But im not sure about this code that is working or not.
Posted
Updated 5-Sep-16 23:35pm
v2
Comments
Afzaal Ahmad Zeeshan 4-Sep-16 14:45pm    
Why is it not working? What is it generating as the output?

1 solution

You can use the below code to create dump using "exp" and c#.
The same may work with "expdp" :


C#
protected void btnExport_Click(object sender, EventArgs e)
    {
        string batchfile = "Docs/batchfile.bat";
        string exportfile = Server.MapPath("Docs/myexport.dmp");
        string exp_cmd = "exp user/pwd@db file='" + exportfile + "' log=a.log tables=(mytable)";

        StreamWriter sw = File.CreateText(Server.MapPath(batchfile));
        sw.WriteLine("@echo off");
        sw.WriteLine(exp_cmd);
        sw.WriteLine("exit");
        sw.Close();

        System.Diagnostics.Process p = System.Diagnostics.Process.Start(Server.MapPath(batchfile));
        p.WaitForExit();
        p.Close();

        Label2.Text = "Exported to : "+exportfile;

    }
 
Share this answer
 

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