Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5951443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:32:15+00:00 2026-05-22T17:32:15+00:00

Hi I’ve used the below code in C# to take the backup of a

  • 0

Hi I’ve used the below code in C# to take the backup of a database in PostgreSQL.This code runs when the backup button is clicked

private void lnkSCBackup_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
 SaveFileDialog save = new SaveFileDialog();              
 save.Filter = "Postgre backups (*.backup)|*.backup";      
 save.ShowDialog();       
 if (save.FileName != "")    
 {  
                string saveFileName = "\"" + save.FileName + "\"";  
                string host =  S ystem.Configuration.ConfigurationSettings.AppSettings["HOST"].ToString().Trim();  
                string port = System.Configuration.ConfigurationSettings.AppSettings["PORT"].ToString().Trim();  
                string userName = System.Configuration.ConfigurationSettings.AppSettings["USERNAME"].ToString().Trim();  
                string password = System.Configuration.ConfigurationSettings.AppSettings["PASSWORD"].ToString().Trim();  
                string dataBase = System.Configuration.ConfigurationSettings.AppSettings["DATABASE"].ToString().Trim();
try 
                {
                    string Creten = "pg_dump -h " + host + " -U " + userName + " -p " + port + " -F c -b -v " + dataBase + " > " + saveFileName;

                    try
                    {
                        // create the ProcessStartInfo using "cmd" as the program to be run,
                        // and "/c " as the parameters.
                        // Incidentally, /c tells cmd that we want it to execute the command that follows,
                        // and then exit.
                        System.Diagnostics.ProcessStartInfo procStartInfo =
                                               new System.Diagnostics.ProcessStartInfo("cmd", "/c " + Creten);

                        // The following commands are needed to redirect the standard output.
                        // This means that it will be redirected to the Process.StandardOutput StreamReader.
                        procStartInfo.RedirectStandardOutput = true;
                        procStartInfo.UseShellExecute = false;
                        // Do not create the black window.
                        procStartInfo.CreateNoWindow = true;
                        // Now we create a process, assign its ProcessStartInfo and start it
                        System.Diagnostics.Process proc = new System.Diagnostics.Process();
                        proc.StartInfo = procStartInfo;
                        proc.Start();
                        proc.WaitForExit();
                        // Get the output into a string
                        string result = proc.StandardOutput.ReadToEnd();
                        //Gets the total processing time for this particular process
                        string totalProcessingTime = proc.TotalProcessorTime.Ticks.ToString();
                        //progress bar working                       
                        progressBar1.Visible = true;
                        progressBar1.BringToFront();
                        progressBar1.Minimum = 0;
                        progressBar1.Maximum = int.Parse(totalProcessingTime);
                        progressBar1.Step = 500;
                        progressBar1.Value = 0;
                        this.lblBackup.Visible = true;
                        this.lblBackup.Text = "Backing Up Database";//To show the user it is backing up
                        this.lblBackup.Font = new Font("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Regular);
                        this.Refresh();
                        while (progressBar1.Value < progressBar1.Maximum)
                        {
                            progressBar1.Value += 10;//= 10000;
                        }
                        progressBar1.Visible = false;
                        this.lblBackup.Visible = false;
                        int exitCode = proc.ExitCode;
                        if (exitCode.Equals(0))
                        {
                            MessageBox.Show("             Backup Success            ");
                        }
                        else
                        {
                            MessageBox.Show("           Backup not Success          ");
                        }

                    }
                    catch (Exception objException)
                    {
                        // Log the exception
                    }
                }

Now my problem is this part of code works fine in my system and the backup is taken properly.
But does not work in another system it finally comes and gets stuck in statement

string result = proc.StandardOutput.ReadToEnd();

Does anyone have an idea why this could happen??The same code not working in different PC’S??? Could this be a PostgreSQL issue

Thanks in advance!!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:32:16+00:00Added an answer on May 22, 2026 at 5:32 pm

    It’s not all strange that “The same code not working in different PC’S”, as different machines can have different environments. For one thing, your are invoking the system command

    pg_dump -h " + host + " -U " + userName + " -p " + port + " -F c -b -v " + dataBase 
    

    Have you checked that it works in the second machine? (i.e. pg_dump is in your path AND you can connect to your pg DB with those parameters)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.