Log In
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
  [Expand]Application Solution Components
   Client-Side Mobile Application
  [Collapse]Business Model Design
    Business Model Design Basics
    Built-in Business Classes for Most Popular Scenarios
   [Expand]Business Model Design with Entity Framework
   [Expand]Business Model Design with XPO
    Non-Persistent Objects
    PropertyChanged Event in Business Classes
   [Expand]Data Types Supported by built-in Editors
    Mapping Complex Types to the Database
   [Expand]Types Info Subsystem
    Connect an XAF Application to a Database Provider
    Data Annotations in Data Model
    Create and Update the Application's Database
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Extend Functionality
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]System Module
  [Expand]Extra Modules
  [Expand]Debugging, Testing and Error Handling
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
This documentation page describes implementations made in our v17.2 release cycle. To learn about functionality shipping with v18.1, navigate to our updated help file experience at docs.devexpress.com. Learn More

Connect an XAF Application to a Database Provider

When an application runs for the first time, its database is created automatically. During the following runs in a debug mode, the application connects to the same database and updates it as required. When the application runs in a release mode, the database is not updated by default. For details, refer to the Create and Update the Application's Database topic. If you ever need to have your database recreated, just drop it from the database server or remove the file, and it will be recreated automatically. By default, an XAF solution is configured to use an instance of the Microsoft SQL Server Express on the local system, accessed via the integrated security. A database will be created on that server under the name of the solution you created. However, XPO, which serves as an Object-Relational Mapping layer, supports over a dozen database management systems. So you can change the default connection. To do this, you need to specify the required connection setting, and reference the required database provider connector assembly. This topic describes several approaches that allow you to connect an XAF application to the required database provider.

Expanded Approach 1. Specify the Connection String via the Application Projects' Configuration Files

When you need to access the connection string in a compiled application, specify it via the application projects' configuration files.

  • App.config - a WinForms application project's configuration file.
  • Web.config - an ASP.NET Web application project's configuration file.

By default, these configuration files contain the connectionStrings section, which has a number of commented sample connection strings. You can uncomment and customize one of the existing connection strings, or specify a new connection string in the following way.


In XPO applications, the initial connection string declaration sets Pooling to false, thus overriding the default true value and disabling SQL Server Connection Pooling. We do not recommend deleting "Pooling = false;" or setting Pooling to true. XPO uses a separate connection with disabled pooling to create a new database. If pooling is enabled, a SQL server attempts to create a database and tries to use an existing connection from the pool. This causes an error, because the connection is not notified that the database was created.

Note that by default, XAF application projects are configured to connect to MS Access and the MS SQL server. However, if you connect to a different server, you need to perform two additional steps.

  1. Reference the required database provider connector assembly in the application projects. The complete list of the assemblies required for different database providers can be found in the Database Systems Supported by XPO document.
  2. Specify an appropriate XpoProvider parameter value in the connection string. The complete list of possible values for different database providers can be found in the How to create a correct connection string for XPO providers? Knowledge Base article.

When the connection string is commented or not specified in a configuration file, the connection string specified in the Application Designer is used by the application. This is provided by the following code, which is automatically added in each XAF solution.


As you can see from the code above, the element named "ConnectionString" is used to obtain the connection string from the configuration file. So do not rename this element unless you change the corresponding string in the application code.

Expanded Approach 2. Specify the Connection String via the Application Designer

You can specify the connection string via the Application Designer's Connection section. Select the Connection item in this section to modify the ConnectionString property in the Properties window. Additionally, you can replace the SQL Connection with another available connection. For this purpose, drag the required connection from the Toolbox to the Connection section, and specify the ConnectionString property as required.

When you drag the required connection from the Toolbox to the Connection section, the required database provider assembly is automatically referenced. If the required connection component is not available, right-click the Toolbox to invoke the Choose Toolbox Items dialog, tick off the required connection component and click Ok.


The connection string specified in the application configuration file overrides the connection string specified in the Application Designer. This is done to provide application administrators with an option to change the database connection without recompiling the application.

Expanded Get the Connection String to a Database

You can obtain properly formatted connection strings via XPO data store adapter classes. These classes are located in the DevExpress.Xpo.DB namespace of the DevExpress.Xpo.v18.1 assembly. Each adapter class contains the GetConnectionString method. Use this method to obtain a connection string to the database using specified parameters. All XPO adapter classes are listed in the Database Systems Supported by XPO topic.

The following code snippet demonstrates how to connect to a "MyApp" MySql database located on the "DBSERVER" server using the "usr" account with the "pwd" password. The MySql.Data assembly must be referenced in the application project.


If you want to specify the connection string using the first or the second approach described above, look at the value returned by the GetConnectionString method in the debugger, and copy it to the Application Designer or the configuration file. Note that a string returned by the GetConnectionString method contains the additional XpoProvider parameter. It identifies the database type to which a connection should be established. So, a string returned by the GetConnectionString method is not fully compatible with the standard connection string format. You can use this connection string in configuration files without modification, but the extra parameter has to be removed to use the string in the Application Designer.

Is this topic helpful?​​​​​​​