Session.ConnectionString Property
Gets or sets a connection string.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v19.2.dll
Declaration
Property Value
Type | Description |
---|---|
String | Data store connection parameters. |
Remarks
If a connection string is a reference to a Data Store Service (URL), Session connects to a Data Store Service client.
Session throws CannotFindAppropriateConnectionProviderException in the following situations:
A connection string does not contain the XpoProvider attribute and XPO cannot infer the provider name from other attributes. | To get a fully qualified connection string, use the GetConnectionString method of a corresponding connection provider. |
A connection string references a Data Store Service and a target platform is .NET Standard or .NET Core. | To connect a .NET Standard/.NET Core project to a Data Store Service, create and configure DataStoreClientAsync or CachedDataStoreClient. For additional information, see WCF Client in .NET Core. |
Do not assign the ConnectionString property value to another Session, because the property may return an empty string or the ConnectionString property value of the underlying IDbConnection object. The underlying connection string does not contain the XpoProvider attribute. To connect Session to the same database, create a new IDbConnection object (see the code example below).
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
public static Session CloneSession(Session source) {
Session result = new Session();
result.AutoCreateOption = AutoCreateOption.DatabaseAndSchema;
result.Connection =
(IDbConnection)Activator.CreateInstance(source.DataLayer.Connection.GetType());
result.Connection.ConnectionString = source.ConnectionString;
return result;
}
Note
To avoid a CannotChangePropertyWhenSessionIsConnectedException, do not change the ConnectionString property value when the IsConnected property returns true.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ConnectionString property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.