SQL Connection Error

Sam Mueller asked on January 11, 2017 16:59

I'm having an issue trying to accessing our staging site. I made a build push of the .proj file, removing a conflicted content include entry of a file that didn't exist in the next iteration to allow the push.

Now I'm getting a SQL Connection Error:

The application could not connect to the database, please check the connection string in the web.config file and SQL server availability.

Original error: [ObjectGenerator.RegisterDefaultFactory]: You cannot change the default type of the generated objects after some objects were created by the generator. 2 objects were already created by this generator. To fix this problem, run the registration sooner in the application life cycle or create new objects later.

The connection string never changed and the SQL server is up. How can I resolve this error?

Correct Answer

Brenden Kehren answered on January 12, 2017 04:55

During code pushes a good rule of thumb is to refresh the app pool manually after the site has been published. The site itself may refresh but the app pool may not and have been cached.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Sam Mueller answered on January 11, 2017 17:30

It seems the issue resolved itself. Not sure how but there must have been a connection issue with the database server or a cached referenced that took some time to update the digested change. I'm chalking it up to the "it just works" theorem.

0 votesVote for this answer Mark as a Correct answer

Killian Walsh answered on June 14, 2017 10:33 (last edited on June 14, 2017 10:33)

Hi,

We're getting the same error on one of our live sites (v9.0.5) in Azure.

Message: [ObjectGenerator.RegisterDefaultFactory]: You cannot change the default type of the generated objects after some objects were created by the generator. 1 objects were already created by this generator. To fix this problem, run the registration sooner in the application life cycle or create new objects later.

Exception type: System.Exception Stack Trace: at CMS.Base.ObjectGenerator`1.RegisterDefaultFactory(IObjectFactory factory, Boolean topPriority) at CMS.Ecommerce.ECommerceModule.OnInit() at CMS.Core.ModuleEntry.Init() at CMS.Core.ModuleEntryManager.Init() at CMS.Core.AppCore.Init() at CMS.DataEngine.CMSApplication.Init()

It happens infrequently and (so far) unpredictably. It's not linked to deployments or traffic levels from what I can tell. The only unusal activity I see in the Event Log is a high rate (dozens per minute) of Application_Start events at certain periods. However the crash does not always occur at these times either.

Any thoughts?

0 votesVote for this answer Mark as a Correct answer

Kurt Schindler answered on June 19, 2017 20:24

I've seen the same thing happen on occasion, and now twice in the last few times I restarted the app. v9.0.50 as well.

This has occurred after deploying .dll changes, as well as just clicking the "Restart application" button in the System application.

What makes matters worse is Kentico appears to cache the sql connection error state, so the whole app goes down for a couple minutes, unless someone intervenes by restarting the app pool/IIS first.

0 votesVote for this answer Mark as a Correct answer

Steven Barker answered on June 21, 2017 14:06

We're also receiving the same error on a v9.0.50 site, the site was previously running in v8 and only seems to have become a problem since the v9 upgrade.

The exact error is as follows: [ObjectGenerator.RegisterDefaultFactory]: You cannot change the default type of the generated objects after some objects were created by the generator. 2 objects were already created by this generator. To fix this problem, run the registration sooner in the application life cycle or create new objects later.

And the full stack trace:

Exception type: System.Exception
Stack Trace: 
at CMS.Base.ObjectGenerator`1.RegisterDefaultFactory(IObjectFactory factory, Boolean topPriority)
at CMS.Ecommerce.ECommerceModule.OnInit()
at CMS.Core.ModuleEntry.Init()
at CMS.Core.ModuleEntryManager.Init()
at CMS.Core.AppCore.Init()
at CMS.DataEngine.CMSApplication.Init()

Message: [ObjectGenerator.RegisterDefaultFactory]: You cannot change the default type of the generated objects after some objects were created by the generator. 4 objects were already created by this generator. To fix this problem, run the registration sooner in the application life cycle or create new objects later.

Exception type: System.Exception
Stack Trace: 
at CMS.Base.ObjectGenerator`1.RegisterDefaultFactory(IObjectFactory factory, Boolean topPriority)
at CMS.Ecommerce.ECommerceModule.OnInit()
at CMS.Core.ModuleEntry.Init()
at CMS.Core.ModuleEntryManager.Init()
at CMS.Core.AppCore.Init()
at CMS.DataEngine.CMSApplication.Init()
at CMS.Base.AbstractHandler.CallEventHandler[TArgs](EventHandler`1 h, TArgs e)
at CMS.Base.AbstractHandler.Raise[TArgs](String partName, List`1 list, TArgs e, Boolean important)
at CMS.Base.SimpleHandler`2.RaiseExecute(TArgs e)
at CMS.Base.SimpleHandler`2.RaiseExecute(TArgs e)
at CMS.Base.SimpleHandler`2.StartEvent(TArgs e)
at CMS.Base.ApplicationModule.BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

As Kurt Schindler said, this problem persists until someone manually recycles the IIS app pool so the live site can be down for some time...

Any help here would be appropriated.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 21, 2017 14:55

Kurt and Steven,

Have you properly registered any custom modules or updated the code from v8 to v9? I'd check this out if you have any custom modules or code you've implemented.

0 votesVote for this answer Mark as a Correct answer

Steven Barker answered on June 22, 2017 15:51

Hi Brenden,

We do have a few custom modules installed on the site, all of our custom modules are registered as such:

[assembly: RegisterModule(typeof (ApiModule))]

namespace NetC
{
    public class ApiModule : Module
    {
        /// <summary>
        ///     Create new instance of ApiModule
        /// </summary>
        public ApiModule() : base("ApiModule")
        {
        }

        /// <summary>
        ///     Initialise the object
        /// </summary>
        protected override void OnInit()
        {
            base.OnInit();

            ...
        }
    }
}

Looking at the stack trace however it seems the problem in both Killian's case and mine lies in the CMS.Ecommerce.ECommerceModule.OnInit() method. We haven't registered any custom objects to be part of the CMS.Ecommerce module.

Thanks, Steven.

0 votesVote for this answer Mark as a Correct answer

Sam Mueller answered on June 30, 2017 14:55 (last edited on June 30, 2017 15:33)

My stack trace also points to CMS.Ecommerce.ECommerceModule.OnInit() and its the same situation, we haven't registered any custom objects to be part of the CMS.Ecommerce module either.

I believe we don't actively use this module but it is attached to all our environments, including production.

Logic would dictate that disabling this module from our site, I would assume this error will subside. I may try disabling it from one of our staging sites and monitor site connectivity for the next couple of weeks in hopes that this error goes away.

0 votesVote for this answer Mark as a Correct answer

Sam Mueller answered on July 6, 2017 14:36

An update:

The error continues to persist even after disabling the Ecommerce module.

0 votesVote for this answer Mark as a Correct answer

Killian Walsh answered on July 7, 2017 12:06

I raised a support ticket with Kentico and sent them some of our custom code. They identified a potential issue with our WCF services and suggested the following...

It seems that problem is with WCF services (files with .svc.cs extension). The service code is calling Kentico API but application initialization is not ensured here. Kentico is initialized automatically for all .NET requests but WCF lifecycle is not attached here.

Therefore it is necessary to call CMS.DataEngine.CMSApplication.Init(); (as described here: https://docs.kentico.com/k10/integrating-3rd-party-systems/using-the-kentico-api-externally#UsingtheKenticoAPIexternally-InitializingtheKenticoapplication) prior any usage of Kentico API within WCF service.

I can't say for sure yet if this has resolved the issue but I will continue to keep an eye on it.

0 votesVote for this answer Mark as a Correct answer

Killian Walsh answered on September 14, 2017 16:33

This doesn't seem to have fixed our issue. The site still drops unpredicatably and the same initialisation errors appear.

0 votesVote for this answer Mark as a Correct answer

Alix Taylor answered on October 13, 2017 17:59

Hi Brendan, we're also experiencing this issue and it's becoming a real issue. We've tried the suggestions about but as with the other guys experience, it made no difference. Please can you advise ASAP?

Thanks Alix.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.