Skip to main content
.NET 6.0+

XpoDefault.GetConnectionPoolString(String, Int32, Int32) Method

Gets a connection pool’s connection string based on a specified standard connection string, pool capacity, and connection limit.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

public static string GetConnectionPoolString(
    string connectionString,
    int poolSize,
    int maxConnections
)

Parameters

Name Type Description
connectionString String

A String value which specifies the parameters required to establish a connection.

poolSize Int32

A connection pool’s capacity (the number of connections to be made available within the pool). If null (Nothing in Visual Basic) is passed as this parameter, the default value (8) is used. If a negative number is passed as this parameter, the pool capacity is unrestricted.

maxConnections Int32

The total number of connections to be established, including the poolSize. If null (Nothing in Visual Basic) or negative number is passed as this parameter, the connection limit is considered unspecified. If the maxConnections is less than the poolSize, the maxConnections is assumed be equal to the poolSize.

Returns

Type Description
String

A String value which specifies the parameters needed to establish a connection pool’s connection.

Remarks

DataStorePool Component

A regular Data Access Layer (DAL) configuration shares a single IDataStore instance between all Session and UnitOfWork objects. When several threads simultaneously execute a read or write operation on Data Access Layer, the first thread executes a query immediately, while the remaining threads have to wait. In high-load applications, such as web sites and web services, use DataStorePool to reduce the waiting time.

Unlike a regular data store, DataStorePool maintains a set of initialized, ready-to-use IDataStore objects. This configuration can serve concurrent read/write operations without delays.

If an application creates a new DAL for every user, they do not have to wait for each other. Note that this approach has a drawback: in a simple configuration, a data layer acquires a database connection and keeps it open, and other threads cannot use this connection object until the application releases it when the user’s session expires. To save SQL server resources and untie database connections from user sessions, change the data layer configuration so that all IDataLayer objects use the same DataStorePool instance.

Activate DataStorePool

The GetConnectionPoolString method returns a connection string with a set of options for DataStorePool. Use this connection string with the GetDataLayer or GetConnectionProvider methods to activate the DataStorePool component.

DataStorePool Options

DataStorePool has the following configuration options:

poolSize
Specifies how many IDataStore instances to keep in a pool. The number of IDataStore instances in use may exceed the poolSize. In this case, DataStorePool destroys redundant instances when clients release them. The poolSize value should be nearly the same as the expected number of simultaneous requests. When the poolSize is small, DataStorePool acquires new connections at the moments of high user activity and releases unused connections when the number of active users is low. Note that the IDataStore instantiation takes some time. You may want to increase the poolSize value to minimize time to instantiate additional IDataStore objects. The default poolSize value is 8. You do not need to change this value in most cases.
maxConnections
Specifies the maximum number of IDataStore instances in use. If the number of IDataStore instances reaches the maxConnections value, DataStorePool suspends subsequent requests and resumes their execution as soon as previous requests release IDataStore instances. The default maxConnections value (-1) allows the DataStorePool to create up to Int32.MaxValue IDataStore instances. You can change the maxConnections value to improve the database performance with many concurrent users.

Example

string connectionString = "Your connection string";

// Here 2 is the number of connections in a pool; 1 connection is not pooled.
// Total is 3 - the maximum number of connections to be established.
string connectionPoolString = XpoDefault.GetConnectionPoolString(connectionString, 2, 3);

IDataStore dataStore = XpoDefault.GetConnectionProvider(connectionPoolString, 
    AutoCreateOption.DatabaseAndSchema);
XPDictionary dictionary = new ReflectionDictionary();

// ...

XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, dataStore);
XpoDefault.Session = null;
See Also