The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ConnectionString Property

Gets or sets the string which is used to open a database.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.1.dll

Declaration

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

Property Value

Type Description
String

A String value which specifies the parameters needed to establish the initial connection.

Property Value

Type Description
String

A String value which specifies the parameters needed to establish the initial connection.

Remarks

A session can establish a connection only if a string assigned to the ConnectionString property contains the XpoProvider parameter, specifying the provider type used for the connection. If this parameter is not specified and XPO cannot determine the provider type using other parameters, a data access layer cannot be created, and as a result, the CannotFindAppropriateConnectionProviderException is thrown. To get a fully qualified connection string for the ConnectionString property, use the GetConnectionString method of a corresponding connection provider. For the InMemoryDataStore, use the InMemoryDataStore.GetConnectionString method instead.

When a session is connected to a data store, the ConnectionString property returns only the connection string that is required to create the underlying IDbConnection, without the XpoProvider parameter entry. So, to create a session based on connection settings of another session, you cannot simply copy its ConnectionString property value. Instead, create the session's connection as shown 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;
}

If a session was instantiated by a data access layer specified either via the corresponding Session constructor or the XpoDefault.DataLayer property, the ConnectionString property returns an empty string.

Note

The ConnectionString property can be modified only when the connection is closed. Otherwise, the CannotChangePropertyWhenSessionIsConnectedException is thrown.

See Also