|
The Pervasive.SQL data providers attaches a data provider-specific prefix to the public .NET objects. For example, the Connection object for the Pervasive.SQL data provider is PsqlConnection.
You connect to a database through the PsqlConnection object, using the method PsqlConnection.Open().
The following example uses the PsqlConnection object to connect to Pervasive.SQL while passing the user name and password:
PsqlConnection mycon = new
PsqlConnection("ServerDSN=Demodata;
UID=test;
PWD=test;
ServerName=localhost;");
mycon.Open();
Table 2-1 lists the connection options supported by the Pervasive.SQL data provider, and describes each option. The connection strings have the form:
For example, the following connection string contains the minimum connection options needed to make the initial connection to the Pervasive.SQL server SERVERDEMO.
NOTES:
|
Option
|
Description
|
|---|---|
|
Alternate Servers
|
Specifies a list of alternate database servers to which the data provider will try to connect if the primary database server is unavailable. Specifying a value for this connection string option enables connection failover for the data provider.
The value you specify must be in the form of a string that defines connection information for each alternate server. You must specify the port number and the name or the IP address of each alternate server. The string has the format:
(Host=hostvalue[, ...])
For example, the following Alternate Servers value defines two alternate servers for connection failover:
Alternate Servers=(Host=AcctServer, Host=AcctServer2;)
See Using Connection Failover for a discussion of connection failover and information about other connection string options that you can set for this feature.
|
|
Connection Lifetime
|
Specifies the number of seconds to keep connections in a connection pool. The pool manager periodically checks all pools, and closes and removes any connection that exceeds its lifetime. The Min Pool Size (page 2-8) option can cause some connections to ignore this value.
Valid values are 0 to 65 335.
The initial default value is 0. The lifetime is never limited by time.
|
|
Connection Reset
|
Connection Reset={true | false}. Specifies whether a connection that is removed from the connection pool for reuse by an application will have its state reset to the state of the new PsqlConnection object. Resetting the state impacts performance of the reused connections because the new connection must issue additional commands to the server.
The initial default value is false.
|
|
Connection Retry Count
|
Specifies the number of times the data provider tries to connect to the primary server, and, if specified, the alternate servers after the initial unsuccessful attempt.
The value can be any integer from 0 to 65535. When set to 0 (the initial default), the data provider does not try to reconnect after the initial unsuccessful attempt.
If a connection is not established during the retry attempts, the data provider returns an error that is generated by the last server to which it attempted to connect.
This option and Connection Retry Delay, which specifies the wait interval between attempts, can be used in conjunction with connection failover. See Configuring Connection Failover for a discussion of connection failover and for information about other connection string options that you can set for this feature.
|
|
Connection Retry Delay
|
Specifies the number of seconds the data provider waits after the initial unsuccessful connection attempt before retrying a connection to the primary server, and, if specified, the alternate servers.
The value can be any integer from 0 to 65535. The initial default is 3 (seconds). When set to 0, there is no delay between retrying the connection.
NOTE: This option has no effect unless the Connection Retry Count connection string option is set to an integer value greater than 0.
This option and the Connection Retry Count connection string option, which specifies the number of times the data provider attempts to connect after the initial attempt, can be used in conjunction with connection failover. SeeConfiguring Connection Failover for a discussion of connection failover and for information about other connection string options that you can set for this feature.
|
|
Encrypt
|
Encrypt={always | never}. Determines whether the data provider uses Encrypted Network Communications, also known as wire encryption.
When Encrypt is not specified in the connection string, the data provider reflects the server's setting, the equivalent of the value "if needed."
If set to always, the data provider uses encryption, or, if the server does not allow wire encryption, returns an error.
If set to never, the data provider does not use encryption and returns an error if wire encryption is required by the server.
|
|
Encryption
|
Encryption={low | medium | high}. Determines the minimum level of encryption allowed by the data provider.
The initial default value is medium.
The meaning of these values depends on the encryption module used. With the default encryption provider, these values correspond to 40-, 56-, and 128-bit encryption, respectively.
|
|
Load Balancing
|
{true | false}. Determines whether the data provider uses client load balancing in its attempts to connect to primary and alternate database servers. The list of alternate servers is specified by the Alternate Servers connection option.
When set to true, the data provider attempts to connect to the database servers in random order. See Client Load Balancing for more information about load balancing.
When set to false (the initial default), client load balancing is not used and the data provider connects to each server based on its sequential order (primary server first, then, alternate servers in the order they are specified).
NOTE: This option has no effect unless alternate servers are defined for the Alternate Servers connection string option.
The Load Balancing connection string option is an optional setting that you can use in conjunction with connection failover. See Configuring Connection Failover for more information for a discussion of connection failover and for information about other connection options that you can set for this feature.
|
|
Max Number Of Pools
|
Specifies the maximum number of connection pools that can be in use at a time during the life of the process.
Valid values are from 1 to 65 335.
The initial default value is 100.
|
|
Max Pool Size
|
Specifies the maximum number of connections within a single pool at any time.
Valid values are from 1 to 65 335.
The initial default value is 100.
|
|
Min Pool Size
|
Specifies the minimum number of connections left open in a connection pool. This option allows you to keep a minimum number of database connections open even though some connections have exceeded their Connection Lifetime (page 2-6) value.
Valid values are 0 to 65 335.
The initial default value is 0.
|
|
Pooling
|
Pooling={true | false}. Specifies whether connections are pooled. When set to true, connection pooling is enabled.
The initial default value is true.
|
|
PWD
|
Specifies a case-insensitive password used to connect to your Pervasive.SQL database. A password is required only if security is enabled on your database. If so, contact your system administrator to get your password.
|
|
ServerDSN
|
The name of the data source on the server, such as ServerDSN=SERVERDEMO.
|
|
ServerName
|
The address of the server or host name and the port number where the data resides. The default port number is 1583.
For example, ServerName=myServer.1583;
|
|
Timestamp
|
Specifies whether Pervasive.SQL timestamps are stored and retrieved as strings in the .NET provider.
When Timestamp is not specified in the connection string (the default), the data provider maps timestamps to DateTime. This setting may be appropriate when native precision is required. For example, when you use the CommandBuilder with timestamp.
When set to String, the data provider maps Pervasive.SQL timestamps as strings.
|
|
UID
|
Specifies the default Pervasive.SQL user name used to connect to your Pervasive.SQL database.
|
The Pervasive.SQL data provider automatically enables connection pooling for your .NET client application. Connection pooling allows you to reuse connections rather than create a new one every time the data provider needs to establish a connection to the underlying database.
You can control connection pooling behavior by using connection string options (see Modifying the Connection Object ). For example, you can define the number of connection pools, the number of connections in a pool, and the number of seconds before a connection is discarded.
Each connection pool is associated with a specific connection string. By default, the connection pool is created when the first connection with a unique, case-sensitive, connection string is closed and needs to be added to a connection pool. The connection pool remains active as long any connections remain open, either in the connection pool, or held explicitly by the application that has references to a connection object that holds an open backend connection.
NOTE: If a new connection is opened and the connection string does not match an existing pool, a new pool must be created when the connection is closed. By using the same connection string, you can enhance the performance and scalability of your application.
In the following C# code fragments, three new PsqlConnection objects are created, but only two connection pools are required to manage them. Note that the first and second connection strings differ only by the value assigned for User ID and Password.
PsqlConnection conn1 = new PsqlConnection(); conn.ConnectionString = "ServerDSN=DEMODATA; UID=test; PWD=test; Server=localhost;" conn1.Open(); // Pool A is created. PsqlConnection conn2 = new PsqlConnection(); conn2.ConnectionString = "ServerDSN=DEMODATA2; UID=lucy; PWD=quake; Server=localhost;" conn2.Open(); // Pool B is created because the connection strings differ. PsqlConnection conn3 = new PsqlConnection(); conn3.ConnectionString = "ServerDSN=DEMODATA; UID=test; PWD=test; Server=localhost;" conn3.Open(); // conn3 goes into Pool A with conn1.
A connection is eligible to be added to a connection pool when an application explicitly calls the Close method for a Connection object. If no corresponding pool exists for the connection string, a pool is created and populated with connections up to the minimum pool size. Additional connections can be added until the maximum pool size is reached.
Only the resources required to maintain the connection to the backend database, for example, the IP socket and connection string information are added to the pool. The Connection object itself is not added.
Note
Close the connection when you are finished using it, using the Close() method of the PsqlConnection object. If you do not explicitly close the connection, it will not be added or returned to the pool.
A connection is removed from a connection pool when it either exceeds its lifetime as determined by the Connection Lifetime connection string option, or when a new connection that has a matching connection string is initiated by the application (PsqlConnection.Open() is called). The connection must currently be unused, and have a valid link to the server.
Before returning a connection from the connection pool to an application, the pool manager checks to see if the connection has been closed at the server. If the connection is no longer valid, the pool manager discards it, and returns another connection from the pool, if one is available and valid.
NOTE: By default, if discarding an invalid connection causes the number of connections to drop below the number specified in the Min Pool Size attribute, a new connection will not be created until an application needs one.
You can modify a connection by specifying connection options. See PsqlConnection Object for information about specifying options through the data provider's PsqlConnection object.
|
Chapter contents
Prev topic: About the Data Provider
|