Back to Devexpress

XpoDefault.ConnectionString Property

xpo-devexpress-dot-xpo-dot-xpodefault-9ffe45d7.md

latest7.3 KB
Original Source

XpoDefault.ConnectionString Property

SECURITY-RELATED CONSIDERATIONS

Do not build or assign a connection string from untrusted input (such as user-entered text). Always validate connection parameters to mitigate CWE-15-related security risks.

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

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public static string ConnectionString { get; set; }
vb
Public Shared Property ConnectionString As String

Property Value

TypeDescription
String

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

|

Remarks

Use the ConnectionString property to specify a connection string for the default Data Access Layer.

The default sessions and newly created sessions will use the specified connection string when they are connected to a data store, as shown in the following code example.

csharp
using DevExpress.Xpo;
using DevExpress.Xpo.DB;

// Retrieve the Microsoft Access database-specific connection string.
XpoDefault.ConnectionString =
    AccessConnectionProvider.GetConnectionString("sample.mdb", "user", "pwd");
// If the default session is connected, disconnect it.
// XpoDefault.Session and Session.DefaultSession can be used interchangeably.
if(XpoDefault.Session.IsConnected) {
    XpoDefault.Session.Disconnect();
}

// The default data access layer is created and connected to the database
// using the connection string.
XpoDefault.Session.Connect();
vb
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB

' Retrieve the Microsoft Access database-specific connection string.
XpoDefault.ConnectionString = _
AccessConnectionProvider.GetConnectionString("sample.mdb", "user", "pwd")
' If the default session is connected, disconnect it.
' XpoDefault.Session and Session.DefaultSession can be used interchangeably.
If XpoDefault.Session.IsConnected Then
    XpoDefault.Session.Disconnect()
End If

' The default data access layer is created and connected to the database
' using the connection string.
XpoDefault.Session.Connect()

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.

XPO_how-to-create-and-use-the-joinoperand-using-linq-to-xpo-and-criteria-operators-e1883/CS/E1883/Program.cs#L15

csharp
static void Main(string[] args) {
    XpoDefault.ConnectionString = MSSqlConnectionProvider.GetConnectionString("(local)", "E1883");
    CreateData();

XPO_how-to-use-custom-sql-queries-as-a-data-source-in-xpo-via-common-table-expressions-cte-e3468/CS/S138124/Program.cs#L14

csharp
DevExpress.Xpo.Logger.LogManager.SetTransport(new ConsoleLogger());
XpoDefault.ConnectionString = MSSqlConnectionProviderWithCte.GetConnectionString(@"(local)", "CTE_Test");

XPO_how-to-load-unique-distinct-data-via-xpo-e1001/CS/Distinct/Form1.cs#L151

csharp
static void Main() {
    DevExpress.Xpo.XpoDefault.ConnectionString = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString(@".\SQLEXPRESS", "Northwind");
    Application.Run(new Form1());

XPO_how-to-track-changes-made-to-persistent-objects-and-write-them-into-a-separate-table-e2419/CS/Q149895/Program.cs#L16

csharp
Application.SetCompatibleTextRenderingDefault(false);
XpoDefault.ConnectionString = SQLiteConnectionProvider.GetConnectionString(@"nwind.sqlite");
Application.Run(new Form1());

winforms-treelist-expression-editor-xpview/CS/E1887/Program.cs#L16

csharp
static void Main() {
    XpoDefault.ConnectionString = InMemoryDataStore.GetConnectionString(@"..\..\data.xml");
    CreateData();

XPO_how-to-track-changes-made-to-persistent-objects-and-write-them-into-a-separate-table-e2419/VB/Q149895/Program.vb#L16

vb
Application.SetCompatibleTextRenderingDefault(False)
XpoDefault.ConnectionString = SQLiteConnectionProvider.GetConnectionString("nwind.sqlite")
Application.Run(New Form1())

XPO_how-to-load-unique-distinct-data-via-xpo-e1001/VB/Distinct/Form1.vb#L146

vb
Shared Sub Main()
    DevExpress.Xpo.XpoDefault.ConnectionString = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString(".\SQLEXPRESS", "Northwind")
    Application.Run(New Form1())

winforms-treelist-expression-editor-xpview/VB/E1887/Program.vb#L17

vb
Sub Main()
    XpoDefault.ConnectionString = InMemoryDataStore.GetConnectionString("..\..\data.xml")
    Call CreateData()

winforms-filtercontrol-implement-ifilteredcomponent/VB/Q200298/Form1.vb#L16

vb
Public Sub New()
    XpoDefault.ConnectionString = AccessConnectionProvider.GetConnectionString("..\..\nwind.mdb")
    InitializeComponent()

See Also

XpoDefault Class

XpoDefault Members

DevExpress.Xpo Namespace