LLI Wiki — My Digital Knowledge Base

SQL Server: SMO error "Cannot convert value Version140" (CompatibilityLevel)

PowerShell error when setting compatibility level 140 through SMO: cause and workarounds.

In PowerShell, setting a database to compatibility level 140 (SQL Server 2017) fails with:

SqlDatabase: Cannot convert value "Version140" to type "Microsoft.SqlServer.Management.Smo.CompatibilityLevel"

Cause

The CompatibilityLevel enumeration of the loaded SMO library does not know the Version140 value: the SMO or SqlServer module version in use is older than this compatibility level.

Solutions

Update-Module SqlServer
ALTER DATABASE [AppDb] SET COMPATIBILITY_LEVEL = 140;
Mastodon LLIMastodon SocialFosstodon