Ticket T426649
Visible to All Users
Duplicate

NullReferenceException occurs in the ModuleUpdater.CreateCommand method in ASP.NET applications

created 8 years ago

Hi Guys,

i just created a new Web Application - and found out that an existing database update does not work anymore. In this updater i used this command:

this.ExecuteScalarCommand("command…", false);

Now inside the the ExecuteScalarCommand the CreateCommand method is called - and here the objectspace Connection property is NULL. This happens because in the new WebApplication XpoDefault.GetConnectionPoolString is used.

Any Info about this?

thx

Answers approved by DevExpress Support

created 8 years ago (modified 7 years ago)

Hello Martin,

UPDATED:
Starting with version 17.2.5, we improved our code to make ModelUpdater methods work correctly when data store pooling is specified in the connection string. Refer to the T587235 ticket for details.
==================

Thank you for your feedback. Currently, updating the database through the ExecuteScalarCommand method is not supported for applications that use the connections pool. We will consider improving this in the future. However, since currently, the Updater class is XPO-independent, this will require significant changes, while your ticket is the first one where this functionality was requested. You can use the following code to get the correct IDbConnection instance in the current version:

C#
using DevExpress.Xpo.DB; using DevExpress.Xpo.Helpers; namespace MainDemo.Module.DatabaseUpdate { public class Updater : ModuleUpdater { public Updater(IObjectSpace objectSpace, Version currentDBVersion) : base(objectSpace, currentDBVersion) { } private ConnectionProviderSql updatingProvider; public override void UpdateDatabaseBeforeUpdateSchema() { base.UpdateDatabaseBeforeUpdateSchema(); DataStorePool pool = ((BaseDataLayer)(((XPObjectSpace)ObjectSpace).Session).DataLayer).ConnectionProvider as DataStorePool; if (pool != null) { updatingProvider = (ConnectionProviderSql)pool.AcquireUpdateSchemaProvider(); } try { // place your updating code here RenameColumn("Payment", "Hours", "Hours1"); } finally { if (pool != null && updatingProvider != null) { pool.ReleaseUpdateSchemaProvider(updatingProvider); updatingProvider = null; } } } protected override System.Data.IDbCommand CreateCommand(string commandText) { if (updatingProvider != null) { IDbCommand command = updatingProvider.Connection.CreateCommand(); command.CommandText = commandText; return command; } else { return base.CreateCommand(commandText); } } ... } }

Please let me know if you find any issue with it.

    Comments (2)

      Any Updates on this?

      Also kindly in Module wizard /Template add a comment about such behavior.

      Dennis Garavsky (DevExpress) 7 years ago

        @Alex: We hope to fix this one without any comments in one of the next versions. In the meantime, disable connection pooling completely or use the solution above. Thanks.

        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.