dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlDump Class
Members Example

In This Topic
    PgSqlDump Class
    In This Topic
    Serves to store a database or its parts as a script and also to restore database from the received script.
    Syntax
    'Declaration
     
    Public NotInheritable Class PgSqlDump 
       Inherits Devart.Common.DbDump
       Implements System.ComponentModel.IComponentSystem.IDisposable 
    Remarks

    PgSqlDump by its behaviour is similar to pg_dump program.

    Use Schema property to specify server schema from database objects will be stored. If Schema property is an empty string all schema will be included into searching condition.

    Use Tables property to specify a list of tables to be stored. If Tables property is an empty string all tables will be included into the dump text. To generate a script call Backup method. The produced script can be viewed in DumpText. To execute the dump script call the Restore method.

    Note: This class is not available in .NET Standard 1.3 compatible assembly. It is available only in the assembly for full .NET Framework and .NET Standard 2.0 compatible assembly.

    This class is available only in Professional Edition. It is not available in Standard and Mobile Editions.

    Example

    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()
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             Devart.Common.DbDump
                Devart.Data.PostgreSql.PgSqlDump

    Requirements

    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

    See Also