.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
The page you are viewing does not exist in the .NET Core 3.0+ platform documentation. This link will take you to the parent topic of the current section.

Session.ConnectionString Property

Gets or sets a connection string.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v20.1.dll

Declaration

public string ConnectionString { get; set; }
Public Property ConnectionString As String

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.

See Also