Reputation: 415
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
Upvotes: 0
Views: 4417
Reputation: 101150
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
Upvotes: 1
Reputation: 4786
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
)
Upvotes: 1