Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to store locally my Postgres database (.backup) using Winform C#.

What I have tried:

C#
string cmd = "-i -h localhost -p 5432 
-U postgres -F c -b -v -f " + "@D:\\DatabaseBackupGrabberDaily\\" + 
"iis_live" + ".backup ";

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
                info.FileName = @"C:\ProgramFiles\PostgreSQL\9.6\bin\pg_dump.exe";
                info.Arguments = cmd;
                info.CreateNoWindow = true;
                info.UseShellExecute = false;
                System.Diagnostics.Process proc = 
                         new System.Diagnostics.Process();
                proc.StartInfo = info;
                proc.Start();                
                proc.WaitForExit();
Posted
Updated 14-Sep-23 2:29am
v3
Comments
Richard MacCutchan 24-Aug-23 5:10am    
Change true to false in the line:
info.CreateNoWindow = true;

and you may be able to see what is going wrong.

We can't tell: we have no access to your system to see what might be going on - and your command requires files in specific places which may not be valid for anyone else's PC.

So it's going to be up to you - I'd start by removing this line:
info.CreateNoWindow = true;
And seeing what happens on the console when it tries
If you can't see anything there, then redirect the output and error streams of the process to either a stream in your app or a file and see if you can see any error messages there.

You need to get error (or otherwise) messages before you can even begin to diagnose the problem, and we really can't do any of that for you!
 
Share this answer
 
Comments
odimaxxx 24-Aug-23 4:18am    
still not working :(
OriginalGriff 24-Aug-23 4:42am    
That's because it's not a solution, it's a way of you finding out what the problem actually is!
You need to look at what the process is saying when you try to execute it - it could be saying "I can't find a D: drive", or "I don't understand that parameter", or "No such file", or "Permissions problem write the file", or anything at all.
And until you know *what* it is saying nobody can fix it!
It's because you're Filename path is wrong. There should be a space between "Program" and "Files".
C#
info.FileName = @"C:\Program Files\PostgreSQL\9.6\bin\pg_dump.exe";
                            ^
 
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