Serves to store a database or its parts as a script and also to restore database from the received script.
The first example creates a PgSqlDump component and executes backup of the tables 'dept','emp' from specified database and schema 'test' using Backup() method. After execution of backup operation the result is saved to the d:\sqldump1.dmp file using the DumpText property.
The second example creates a PgSqlDump component and executes backup of the specified database using Backup(String) method. After execution of backup operation the result is saved directly to the file, specified with the Backup(String) method parameter.
Note: If you want to backup a database, containing a large amount of data, it is not recommended to use the DumpText property for storing the backup script. Better use Backup(Stream), Backup(TextWriter), Backup(String) overloaded methods.
// First example
PgSqlConnection conn = new PgSqlConnection("user id = postgres;password=postgres;host=localhost;port=5432;database =testbase;schema=test");
conn.Open();
PgSqlDump pgSqlDump = new PgSqlDump();
pgSqlDump.Connection = conn;
pgSqlDump.Schema = "test";
pgSqlDump.Tables = "dept;emp";
pgSqlDump.IncludeDrop = true;
pgSqlDump.Backup();
StreamWriter stream = new StreamWriter("d:\\sqldump1.dmp");
stream.WriteLine(pgSqlDump.DumpText);
stream.Close();
conn.Close();
// Second example
PgSqlConnection conn = new PgSqlConnection("user id = postgres;password=postgres;host=localhost;port=5432;database =testbase;schema=test");
conn.Open();
PgSqlDump pgSqlDump = new PgSqlDump();
pgSqlDump.Connection = conn;
pgSqlDump.Backup("d:\\sqldump1.dmp");
conn.Close();
' First example
Dim conn As PgSqlConnection = New PgSqlConnection("user id = postgres;password=postgres;host=localhost;port=5432;database =testbase;schema=test")
conn.Open()
Dim pgDump As PgSqlDump = New PgSqlDump
pgDump.Connection = conn
pgDump.Schema = "test"
pgDump.Tables = "dept;emp"
pgDump.IncludeDrop = True
pgDump.Backup()
Dim stream As StreamWriter = New StreamWriter("d:\\sqldump1.dmp")
stream.WriteLine(pgDump.DumpText)
stream.Close()
conn.Close()
' Second example
Dim conn As PgSqlConnection = New PgSqlConnection("user id = postgres;password=postgres;host=localhost;port=5432;database =testbase;schema=test")
conn.Open()
Dim pgDump As PgSqlDump = New PgSqlDump
pgDump.Connection = conn
pgSqlDump.Backup("d:\\sqldump1.dmp")
conn.Close()
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2