KB Article T367835
Visible to All Users

How to avoid compatibility errors during the database update or application startup

Scenario

Call Stack
System.InvalidOperationException: The application cannot connect to the specified database, because the database doesn't exist, its version is older than that of the application or its schema does not match the ORM data model structure. To avoid this error, use one of the solutions from the https://www.devexpress.com/kb=T367835 KB Article. at DevExpress.ExpressApp.XXXApplication.OnDatabaseVersionMismatch(DatabaseVersionMismatchEventArgs args) at DevExpress.ExpressApp.XafApplication.CheckCompatibilityCore() at DevExpress.ExpressApp.XafApplication.CheckCompatibility()

Error 1. The application cannot connect to the specified database, because the database doesn't exist, its version is older than that of the application or its schema does not match the ORM data model structure.

This error commonly occurs for one of these reasons:
    - the database doesn't exist yet and needs to be created;
    - the database schema does not match the ORM data model structure;
    - the database version is older than that of the application;
    - the database cannot be accessed due to some internal error *unrelated* to the database update or schema compatibility.

Consider one of the following common solutions depending on the situations below.

1.1. If there is an "Inner exception: …"  section at the bottom of this message or in  the eXpressAppFramework.log file (both production and development environments)

This section usually refers to an internal error unrelated to the database update or schema compatibility. Internal errors can quite often be caused by a misconfigured database server, assembly loading failures, connection string or missing database security permissions for the application user identity.
To avoid these internal errors,  try googling the internal error message text for solutions. For instance, you can learn more on this from the Deployment > Deployment Tutorial > Database Security References article and other help sources.

1.2. Production environment (when deploying)

Create or update the database schema as described in the following help topic: Application Update (use the DBUpdater tool for WinForms and WebForms apps or the -updateDatabase -silent -forceUpdate command for Blazor and Web API Service apps respectively).

1.3. Development environment

Start the application from Visual Studio with the debugger attached, because by default, our new application templates (v15.2+) use a simpler and more convenient way to check database compatibility (see XafApplication.CheckCompatibilityType) and are configured to always update the database when System.Diagnostics.Debugger.IsAttached is true.

C#
CheckCompatibilityType = DevExpress.ExpressApp.CheckCompatibilityType.DatabaseSchema;

OR
In the YourSolutionName.Wxx/WxxApplication.xx file, modify the the XafApplication.DatabaseVersionMismatch event handler code to explicitly enable automatic database update on each run:

C#
private void MainDemoWinApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e) { e.Updater.Update(); e.Handled = true; }

Note:  this code modification is suitable for testing during development only. It is NOT suitable for production, because automatic database updates by the main application are not desirable in this case (it is advisable to use separate administrative tools like DBUpdater for that purpose).

Error 2. Database is designed for the A application while you are running the B application

This exception occurs when the XafApplication.CheckCompatibilityType property is set to ModuleInfo and your ApplicationName does not match the application name stored in the ModuleInfo database table. This issue may occur if you changed the ApplicationName  property in code after the application was deployed and if the same database is used by multiple XAF applications. Use one of the following solutions to avoid this error:

  1. If you do not have  a special database versioning logic around the ModuleInfo table, set the XafApplication.CheckCompatibilityType property to 'DatabaseSchema' (v15.2+).
  2. Make sure the XafApplication.ApplicationName property value matches the value stored in the corresponding row of the ModuleInfo database table (a row with the True value in the IsMain column). You can change either one of them. If the database is used by multiple XAF applications, set the XafApplication.ApplicationName property to the same value in all applications. You can apply these changes using the Application Designer or in code.

Error 3. Cannot update the application when the XafApplication.CheckCompatibilityType property is set to DatabaseSchema. Please set this property to ModuleInfo, or disable the application update using the configuration file's NewVersionServer option.

The automatic Application Update mechanism works only when the XafApplication.CheckCompatibilityType property is set to ModuleInfo. In this mode the ModuleInfo table is maintained in the database, which allows the updater to compare actual and expected module versions and trigger the client application update when versions do not match. By default, all new projects use the DatabaseSchema compatibility checking mode. In this mode the ModuleInfo table is not created in the database and automatic application update is not possible. To avoid the issue, either disable the automatic application update by clearing the NewVersionServer value in the configuration or set the CheckCompatibilityType property to ModuleInfo.

Error 4. The client application cannot connect to the Middle Tier Application Server and its database.

When the application server is in use, the compatibility check is performed at the server side. You should unconditionally throw an exception when the XafApplication.DatabaseVersionMismatch event occurs.

If the DatabaseVersionMismatch event handler throws the exception at the client, please ensure that both client and server have the same modules set. Refer to the Visual Studio Output window content or see the client application log (eXpressAppFramework.log). For instance, the following message indicates that the SystemAspNetModule module is not added to the server's Modules collection. (The missing module version is displayed as "0.0.0.0".)
module 'SystemAspNetModule' (DevExpress.ExpressApp.Web.v19.1). Local version: 19.1.6.0, Version on DB: 0.0.0.0
To fix the issue, add this module to the ServerApplication.Modules collection as shown in the Create and Configure the Server topic.

Your feedback is needed

If you experience any difficulties, please contact our Support Team at https://www.devexpress.com/ask and describe in detail how you used the aforementioned solutions for your situation and which actual results or difficulties you had with them.

Show previous comments (10)

    PS.: for Gosha: I actually sometimes run the module from the Azure App Console when manually updating for some debugging reason, and never needed the -silent flag, it just does it

    DevExpress Support Team 3 years ago

      Hi,

      From what I gather, you managed to get the required behavior. If you still have questions, please elaborate on them.

        Yes, thanks. Still tweaking to manage multiple environments, but it does the job.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.