If you need to choose which data provider for PostgreSQL to use with dotConnect Universal, we recommend using dotConnect for PostgreSQL because of its obvious advantages. This article provides a brief overview of dotConnect for PostgreSQL, describes some useful features and helps you get started quickly.
dotConnect for PostgreSQL is a full-featured 100% managed ADO.NET data provider for the .NET Framework and the .NET Compact Framework. dotConnect for PostgreSQL is acknowledged as the leading ADO.NET data provider for PostgreSQL, and it has many advantages over any rival product. The main features of dotConnect for PostgreSQL are:
The full list of dotConnect for PostgreSQL features can be found on the product page.
The Developer Edition of dotConnect Universal includes dotConnect for PostgreSQL as a bundled provider. The Trial Edition includes trial dotConnect for PostgreSQL Data Provider as well. For Express Edition of dotConnect Universal, dotConnect for PostgreSQL Data Provider should be purchased and installed separately.
dotConnect Universal is compatible with dotConnect for PostgreSQL version 4.00 and above.
To deploy applications written with dotConnect Universal, copy the run-time assemblies Devart.Data.Universal.dll and Devart.Data.Universal.PostgreSql.dll to target machine. If you are using the standalone (not bundled) dotConnect for PostgreSQL Data Provider, you will also have to deploy its Devart.Data.PostgreSql.dll assembly.
These assemblies can be registered at the Global Assembly Cache (GAC) for the appropriate .NET Framework or placed in the folder of your application.
For web projects, you may also need to deploy the Devart.Data.Universal.Web.dll, Devart.Data.PostgreSql.Web.dll and App_Licenses.dll assemblies. The *.Web.dll assemblies are required for using the ASP.NET Provider Model and the App_Licenses.dll assembly is a part of licensing mechanism.
Web projects are usually run as partially trusted code. dotConnect Universal and dotConnect for PostgreSQL require medium trust plus ReflectionPermission and SocketPermission.
Suppose you want to connect to a PostgreSQL server running on the host server, at the port 5432, with the user name postgres and the password mypassword. Suppose also that you would like to work within schema Public and use postgres as the default database. In this case your connection string would look like this:
Provider=PostgreSQL;host=server;port=5432;user=postgres;password=mypassword;initial schema=Public;database=postgres
The initial schema parameter is Public by default; the port parameter defaults to 5432 as well. If the database parameter is not specified, it is assumed that name of the database is same as user name. So basically you need only host name, user name and password:
Provider=PostgreSQL;host=server;user=postgres;password=mypassword
The following table enumerates most important connection string parameters.
| Name | Description |
|---|---|
| AllowDateTimeOffset | Determines whether to use the DateTimeOffset type instead of DateTime when reading a timestamptz value. |
| ApplicationName | Specifies the client application name. |
| Character Set | Specifies the character set used by the client. When set, a "SET NAMES <charset>" query is executed on establishing a connection. The default value is an empty string, which means no action is performed with the charset. |
| Connect Timeout -or- Connection Timeout | Specifies the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. The default value is 15. |
| Connection Lifetime | Specifies the maximum lifetime (in seconds) of a pooled connection. When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span exceeds the value specified by Connection Lifetime. The default value is 0. |
| Data Source -or- Host -or- Server | Specifies the name or IP address of the host of the PostgreSQL database to which to connect. |
| Database | Specifies the name of the database. If this parameter is not specified, it is assumed that the name of the database is the same as the user name. |
| Default Command Timeout | Specifies the default time (in seconds) to wait while trying to execute a command before terminating the attempt and generating an error. A value of 0 indicates no limit. |
| Default FetchAll | Specifies the default value of the FetchAll property for commands created on the connection. When enabled, the data reader retrieves all queried data from the server on execution. |
| Enlist | Determines whether the connection is automatically enlisted in the current distributed transaction. The default value is true. |
| Force IPv4 | Determines whether authentication by an IPv6 address is allowed, or an IPv4 address is always used. The default value is false. |
| Ignore Unnamed Parameters | Specifies whether to disable treating the '?' character in CommandText as an unnamed parameter. |
| Initial Schema | Specifies the name of the schema to be used once a connection is opened. You can change it later if you need. The default schema is 'Public'. |
| Initialization Command | Specifies a database-specific command that should be executed immediately after establishing the connection. |
| Integrated Security | Determines whether to use secure authentication with single sign-on (GSSAPI or SSPI, depending on the server). |
| Join Statement Notices | Determines whether all notices raised during statement execution are returned together in one InfoMessage event, or each notice is returned in a separate event. |
| Keep Alive | Specifies whether to send TCP keep-alive packets and the interval (in seconds) at which they are sent. The default value is 0, which means the packets are not sent. |
| Keep Connected | Specifies whether to perform periodic ping calls to PostgreSQL when a connection is inactive, and the interval (in seconds) at which the calls are made. The default value is 0, which means the calls are not made. |
| Max Pool Size | Specifies the maximum number of connections allowed in the pool. Setting the Max Pool Size value of the ConnectionString can affect performance. The default value is 100. |
| Min Pool Size | Specifies the minimum number of connections allowed in the pool. The default value is 0. |
| Password | Specifies the password for the PostgreSQL login account. |
| Persist Security Info | Determines whether security-sensitive information, such as the password, is retained in the connection string after the connection has been opened. |
| Pooling | Determines whether, by default, the UniConnection object is drawn from the appropriate pool or is created and added to the appropriate pool. The default value is true. |
| Port | Specifies the port of the PostgreSQL database to which to connect. The default value is 5432. |
| Protocol | Specifies the Frontend/Backend Protocol version. Available values are 2 and 3. Set the parameter to 2 for the protocol version 2.0 or to 3 for protocol version 3.0. Can be applied only for PostgreSQL server versions 7.4 or higher, for PostgreSQL earlier versions this parameter is ignored. To execute several statements in the same query set procol to 2 version. The default value is 3. |
| Proxy Host | Specifies the host name or IP address of the proxy server. |
| Proxy Password | Specifies the password for the proxy server account. |
| Proxy Port | Specifies the port number of the proxy server. The default value is 3128. |
| Proxy User | Specifies the proxy server account name. |
| Run Once Command | Specifies a database-specific command that should be executed immediately after establishing the connection. Unlike Initialization Command, it is not executed for connections obtained from the connection pool. |
| SSH Authentication Type | Specifies the client's SSH authentication method. |
| SSH Cipher List | Specifies the list of ciphers that the client agrees to use, separated by colons. |
| SSH Host | Specifies the name or IP address of the SSH server. |
| SSH Host Key | Specifies the location of the public key on the client side used to verify the server host key during connection establishment. OpenSSH or IETF SECSH key files are supported. You may use such utilities as 'ssh-keygen.exe' or 'puttygen.exe' for generation of the corresponding public/private key pair. |
| SSH KeyExchange Algorithms | Specifies the algorithms used to securely establish a shared encryption key between the client and the server. |
| SSH MAC Algorithms | Specifies the algorithms used to verify the integrity and authenticity of data exchanged between the client and the server. |
| SSH Passphrase | Specifies the client key passphrase. |
| SSH Password | Specifies the user password on the SSH server. |
| SSH Port | Specifies the number of the port on the SSH server to connect to. |
| SSH Private Key | Specifies the location of the private key, which is used by the client to sign data and by the server to authenticate the user. |
| SSH Strict Host Key Check | Indicates whether the host key is verified during establishing connection. |
| SSH User | Specifies the user id on the SSH server. |
| SSL CA Cert | Specifies the location of the authority certificate. |
| SSL Cert | Specifies the location of the client certificate. |
| SSL Cipher List | Specifies the list of ciphers that the client agrees to use. |
| SSL Key | Specifies the location of the user's private key. |
| SSL TLS Protocol | Specifies the preferred TLS protocol version, reported to the server when establishing a secure connection. |
| SSLMode | Specifies the SSL connection priority. May be Disable, Allow, Prefer, and Require. The default value is Disable, which means that only an unencrypted SSL connection will be attempted. |
| Target Session | Determines how the host to connect to is selected from the list when multiple hosts are specified in the Host connection string parameter. |
| Transaction Error Behavior | Determines whether to roll back a transaction automatically when an error occurs inside the transaction. |
| Transaction Scope Local | Restricts all connections within a TransactionScope object to a single internal connection when several connections use the same connection string. The default value is false. |
| Unicode | Sets the client charset to UTF8 and converts client data according to this charset when set to true, by default. |
| Unprepared Execute | Enables the unprepared execute mode by default in UniCommand instances when set to true. |
| Use Session Timezone | Specifies whether the current session's time zone is used to convert the requested PostgreSQL date/time values. |
| User ID -or- User | Specifies the PostgreSQL login account. |
| Validate Connection | Specifies whether to validate connections that are retrieved from the pool. |
To get up and running quickly, you have to perform the following steps:
That's all you need to start executing queries on the server. Below is a code fragment that illustrates steps 2-5. It also shows how to perform INSERT and SELECT operations.
dotConnect Universal supports handling PostgreSQL BLOBs. For detailed information on how to work with BLOB objects, refer to the Working with BLOB Data article.
dotConnect Universal supports using the UniDecimal structure with PostgreSQL. Use the reference to find out how to manage big numbers on client side.
It is also possible to take advantage of special network capabilities of dotConnect for PostgreSQL by setting up the connection string parameters. This way you can enable:
dotConnect for PostgreSQL supports all features of UniSQL, except for the DATEDIFF unified function name. Use PostgreSQL and PostgreSQLDirect predefined macros to build conditional UniSQL statements. For more information refer to the UniSQL topic.
The following table shows how the UniDbType enumeration maps to the PostgreSQL database type.
| UniDbType | PostgreSQL Type |
|---|---|
| BigInt | BIGINT |
| Binary | BYTEA |
| Bit | BIT |
| Blob | BYTEA |
| Boolean | BOOLEAN |
| Byte | SMALLINT |
| Char | CHAR |
| Clob | TEXT |
| Currency | CURRENCY |
| Date | DATE |
| DateTime | TIMESTAMP |
| Decimal | NUMERIC |
| Double | DOUBLE |
| Guid | VARCHAR |
| Int | INTEGER |
| IntervalDS | INTERVAL |
| IntervalYM | INTERVAL |
| NChar | CHAR |
| NClob | TEXT |
| NVarChar | VARCHAR |
| Single | REAL |
| SmallInt | SMALLINT |
| TinyInt | SMALLINT |
| Time | TIME |
| TimeStamp | TIMESTAMP |
| VarChar | VARCHAR |
| Xml | VARCHAR |
For more information on dotConnect for PostgreSQL Data Provider please visit the following locations:
Using dotConnect Universal with SQL Client | Using dotConnect Universal with dotConnect for Oracle | Using dotConnect Universal with dotConnect for MySQL | Using dotConnect Universal with dotConnect for SQLite