0

I've got application which contains a database based on Postgresql. I wannna get a backup of this database using my application. for ex. I wanna click an option in program menu and wanna get file with database backup. I got all administratior rights for this database. Application is wrtitten in .net 4.0 (C#), windows forms.

How could I solve my problem?


i' ve tried it but it's not working:

 string zapytanie = @"pg_dump WFR > C:\kopia";
                string pol = Ustawienia.ConnectionString;
                NpgsqlConnection conn = new NpgsqlConnection(pol);
                conn.Open();
                NpgsqlCommand comm = conn.CreateCommand();
                comm.CommandText = zapytanie;

                comm.ExecuteNonQuery();
                conn.Close();

errors:

ERROR: 42601: syntax error at or near "pg_dump"

stacktrace:

w Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext()
   w Npgsql.ForwardsOnlyDataReader.GetNextResponseObject()
   w Npgsql.ForwardsOnlyDataReader.GetNextRowDescription()
   w Npgsql.ForwardsOnlyDataReader.NextResult()
   w Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError)
   w Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
   w Npgsql.NpgsqlCommand.ExecuteNonQuery()
   w Faktury_i_Rachunki_2.Forms.FrmKopiaBezp.BtUtworzKopie_Click(Object sender, EventArgs e) w D:\nwfr3\Faktury i Rachunki 2.0\Forms\FrmKopiaBezp.cs:wiersz 38
3
  • 1
    Have you tried to read the postgre manual? first hit in Google when searching for postgresql backup command. Explain why if those commands are not enough for you Commented Apr 26, 2012 at 7:30
  • i' ve tried it but it's not working: string zapytanie = @"pg_dump WFR > C:\kopia"; string pol = Ustawienia.ConnectionString; NpgsqlConnection conn = new NpgsqlConnection(pol); conn.Open(); NpgsqlCommand comm = conn.CreateCommand(); comm.CommandText = zapytanie; comm.ExecuteNonQuery(); conn.Close(); Commented Apr 26, 2012 at 8:09
  • add that to your question (formatted) and not as a comment. also include any error messages Commented Apr 26, 2012 at 8:12

2 Answers 2

1

Maybe you can include a copy of pg_dump.exe binary for Ms Windows (and required dlls) with your application. Then invoke it with proper parameters from a GUI.

(you can use Dependency Walker to find out what libraries are required by pg_dump.exe)

Sign up to request clarification or add additional context in comments.

Comments

1

pg_dump is a tool and not a SQL command. You need to execute it using Process.Start.

pg_dump outputs a SQL script. So you need some way to capture the SQL script form standard out. It can be achieved in the following way: http://www.c-sharpcorner.com/UploadFile/edwinlima/SystemDiagnosticProcess12052005035444AM/SystemDiagnosticProcess.aspx

1 Comment

Thank you for help. I'll check it and when I get solution, I'll paste here. Have a nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.