· Uwe Janke
Commands / Repair-sqmSsasSerializeError

Repair-sqmSsasSerializeError

Cluster & Services sqmSQLTool v1.9.126+ · Repair ✓ -WhatIf supported · Medium Impact
Deploying an XMLA <Create>/<Alter> script to SQL Server Analysis Services can fail with Internal error: An unexpected error occurred (file 'pcserialize.cpp', line 1535, function 'ASDatabase::Serialize'), most often reported on instances that sit inside an Always On Availability Group. The message itself gives no clue what is wrong.
The confirmed cause and fix: an undocumented <Gen2ServerKey> element in msmdsrv.ini (see Microsoft Q&A 1350375). Its purpose is unclear and no side effects have been reported from removing it — doing so and restarting the service makes the serialization error disappear. This function locates msmdsrv.ini, backs it up, removes the element if present, and optionally restarts the service.

Parameters

ParameterTypeRequiredDefaultNotes
-InstanceNamestringOptionalMSSQLSERVERSSAS instance name. A "Server\Instance" prefix (as copied from SSMS) is accepted and the server part is ignored.
-RestartServiceswitchSwitch$falseRestart the SSAS service so the fix takes effect immediately. Without it, the change is written but the serialization error keeps occurring until the next manual restart.
-EnableExceptionswitchSwitch$falseThrow immediately instead of logging the error and returning it in the result.

Execution Flow

START "Server\Instance" given? → keep only the instance part SSAS service found? NO Status=Error service not found YES Resolve <ConfigDir>\msmdsrv.ini via the service command line -s "<dir>" switch, else fallback from the exe path Not found / ini missing → Status=Error Load msmdsrv.ini → locate <Gen2ServerKey> node Whitespace preserved on load, to keep the diff minimal /ConfigurationSettings/Gen2ServerKey Gen2ServerKey present? NO Status=NotPresent nothing to remove → return YES ShouldProcess? (ConfirmImpact: Medium) WhatIf Status=WhatIf nothing written YES Copy-Item → msmdsrv.ini.bak_<timestamp> (backup first) configNode.RemoveChild(Gen2ServerKey), xml.Save(iniPath) Status=Removed -RestartService set? NO Message notes: manual restart needed to take effect YES Restart-Service -Force ServiceRestarted = $true restart itself fails → ERROR logged, Status stays Removed (ini write already done) Return $result Any error above → Status=Error, logged + Write-Error, or throw with -EnableException DONE — result returned

Output object

FieldContents
InstanceName / ServiceName / IniPathWhich instance, its Windows service name, and the config file that was read/changed.
BackupPathPath of the msmdsrv.ini backup — only set when a change was actually written.
ServiceRestartedWhether the SSAS service was restarted.
StatusNotPresent, Removed, WhatIf, or Error.
MessageDetail message.

Examples

Fix the default instance and apply it immediately
Repair-sqmSsasSerializeError -RestartService
Check a named instance without changing anything
Repair-sqmSsasSerializeError -InstanceName "SSAS2019" -WhatIf
Write the fix now, restart the service on the next maintenance window
Repair-sqmSsasSerializeError -InstanceName "SSAS2019"

Requirements

Requires local administrator rights on the SSAS server. Idempotent: a second run against an already-fixed instance reports NotPresent instead of re-touching msmdsrv.ini. Background: Microsoft Q&A 1350375.

See also

Get-sqmSsasDeploymentMode / Set-sqmSsasDeploymentMode, same msmdsrv.ini discovery for the SSAS server mode. Test-sqmSsasDirectoryPermissions, for a different class of SSAS setup problem (NTFS permissions).