When trying to enable "Workflow Can Use App Permissions" under Site Settings=> Manage Site Features => then trying to activate the feature, I found the following exception occurs:
Exception information:
Exception type: SPException
Exception message: We're sorry, we weren't able to complete the operation, please try again in a few minutes. If you see this message repeatedly, contact your administrator.
at Microsoft.SharePoint.SPScaleOutDatabaseMap.CreateSqlSession(ISPScaleOutDatabaseMapProvider mapProvider, Byte[] compositeKey, Guid forceRefreshVersion, Guid& version)
at Microsoft.SharePoint.SPScaleOutDatabaseCommandExecutor.Execute(ExecuteDelegate operation, ISPScaleOutDatabaseMapProvider mapProvider, SPSqlCommand command, Byte[] compositeKey)
at Microsoft.SharePoint.AppManagement.AppManagementServiceApplicationProxy.PutApp(SPAppPrincipalInfo appInfo)
at Microsoft.SharePoint.AppRegistration.AddOrUpdateAppNoPermissionCheck(SPAppPrincipalInfo appInfo)
at Microsoft.SharePoint.SPAppPrincipalManager.RegisterWithInternalDirectory(SPAppPrincipalIdentityProvider identityProvider, String nameIdentifier, String displayName, List`1 appEndpointAuthorities, List`1 redirectAddresses, Boolean delegateAppPermissions, Boolean isInternalDirectoryApp)
at Microsoft.SharePoint.SPAppPrincipalManager.CreateAppPrincipal(SPExternalAppPrincipalCreationParameters creationParameters)
at Microsoft.SharePoint.WorkflowServices.SPWebWorkflowSecurityContext.EnsureAppPrincipal(SPWeb elevatedWeb)
at Microsoft.SharePoint.WorkflowServices.SPWebWorkflowSecurityContext.<>c__DisplayClass1.b__0()
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)
at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)
at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)
at Microsoft.SharePoint.SPFeatureCollection.AddInternalWithName(Guid featureId, Int32 compatibilityLevel, String featureName, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly, SPFeatureDefinitionScope featdefScope)
at Microsoft.SharePoint.WebControls.FeatureActivator.ActivateFeature(Guid featid, Int32 compatibilityLevel, SPFeatureDefinitionScope featdefScope)
at Microsoft.SharePoint.WebControls.FeatureActivatorItem.ToggleFeatureActivation()
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Also, Same exception appeared while trying to publish SharePoint 2013 Workflow. I tried to find a related events in the Event Viewer and I found a lot of exceptions related to "App Management Service" service application in SharePoint and I found most of exceptions was related the SQL login fail to the backend database. So, in that case, All you need is to check user permission to the database. Or simply delete the current App Management Service from central administration by going to Application Management, under Service Application click on Manage Service Application. In the page click on App Management Service then click delete from the ribbon. Then, you can go to the configuration wizard again at the left of the central administration and start the configuration again.
Please refer to http://technet.microsoft.com/en-us/library/fp161236.aspx
Also, Please be cautious at the live environment, the above steps are tested at the development environment.
Exception information:
Exception type: SPException
Exception message: We're sorry, we weren't able to complete the operation, please try again in a few minutes. If you see this message repeatedly, contact your administrator.
at Microsoft.SharePoint.SPScaleOutDatabaseMap.CreateSqlSession(ISPScaleOutDatabaseMapProvider mapProvider, Byte[] compositeKey, Guid forceRefreshVersion, Guid& version)
at Microsoft.SharePoint.SPScaleOutDatabaseCommandExecutor.Execute(ExecuteDelegate operation, ISPScaleOutDatabaseMapProvider mapProvider, SPSqlCommand command, Byte[] compositeKey)
at Microsoft.SharePoint.AppManagement.AppManagementServiceApplicationProxy.PutApp(SPAppPrincipalInfo appInfo)
at Microsoft.SharePoint.AppRegistration.AddOrUpdateAppNoPermissionCheck(SPAppPrincipalInfo appInfo)
at Microsoft.SharePoint.SPAppPrincipalManager.RegisterWithInternalDirectory(SPAppPrincipalIdentityProvider identityProvider, String nameIdentifier, String displayName, List`1 appEndpointAuthorities, List`1 redirectAddresses, Boolean delegateAppPermissions, Boolean isInternalDirectoryApp)
at Microsoft.SharePoint.SPAppPrincipalManager.CreateAppPrincipal(SPExternalAppPrincipalCreationParameters creationParameters)
at Microsoft.SharePoint.WorkflowServices.SPWebWorkflowSecurityContext.EnsureAppPrincipal(SPWeb elevatedWeb)
at Microsoft.SharePoint.WorkflowServices.SPWebWorkflowSecurityContext.<>c__DisplayClass1.
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)
at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)
at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)
at Microsoft.SharePoint.SPFeatureCollection.AddInternalWithName(Guid featureId, Int32 compatibilityLevel, String featureName, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly, SPFeatureDefinitionScope featdefScope)
at Microsoft.SharePoint.WebControls.FeatureActivator.ActivateFeature(Guid featid, Int32 compatibilityLevel, SPFeatureDefinitionScope featdefScope)
at Microsoft.SharePoint.WebControls.FeatureActivatorItem.ToggleFeatureActivation()
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Also, Same exception appeared while trying to publish SharePoint 2013 Workflow. I tried to find a related events in the Event Viewer and I found a lot of exceptions related to "App Management Service" service application in SharePoint and I found most of exceptions was related the SQL login fail to the backend database. So, in that case, All you need is to check user permission to the database. Or simply delete the current App Management Service from central administration by going to Application Management, under Service Application click on Manage Service Application. In the page click on App Management Service then click delete from the ribbon. Then, you can go to the configuration wizard again at the left of the central administration and start the configuration again.
Please refer to http://technet.microsoft.com/en-us/library/fp161236.aspx
Also, Please be cautious at the live environment, the above steps are tested at the development environment.