Skip to content

Commit d638be6

Browse files
committed
Add validation for CatalogCollation parameter and error message for unsupported SQL Server versions
1 parent d754bb3 commit d638be6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

source/Public/New-SqlDscDatabase.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@ function New-SqlDscDatabase
187187
}
188188
}
189189

190+
# Validate CatalogCollation if specified (requires SQL Server 2019+)
191+
if ($PSBoundParameters.ContainsKey('CatalogCollation'))
192+
{
193+
if ($ServerObject.VersionMajor -lt 15)
194+
{
195+
$errorMessage = $script:localizedData.Database_CatalogCollationNotSupported -f $ServerObject.InstanceName, $ServerObject.VersionMajor
196+
197+
$PSCmdlet.ThrowTerminatingError(
198+
[System.Management.Automation.ErrorRecord]::new(
199+
[System.InvalidOperationException]::new($errorMessage),
200+
'NSD0005', # cspell: disable-line
201+
[System.Management.Automation.ErrorCategory]::InvalidOperation,
202+
$CatalogCollation
203+
)
204+
)
205+
}
206+
}
207+
190208
$verboseDescriptionMessage = $script:localizedData.Database_Create_ShouldProcessVerboseDescription -f $Name, $ServerObject.InstanceName
191209
$verboseWarningMessage = $script:localizedData.Database_Create_ShouldProcessVerboseWarning -f $Name
192210
$captionMessage = $script:localizedData.Database_Create_ShouldProcessCaption

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ ConvertFrom-StringData @'
357357
Database_AlreadyExists = Database '{0}' already exists on instance '{1}'.
358358
Database_InvalidCompatibilityLevel = The specified compatibility level '{0}' is not a valid compatibility level for the instance '{1}'.
359359
Database_InvalidCollation = The specified collation '{0}' is not a valid collation for the instance '{1}'.
360+
Database_CatalogCollationNotSupported = The parameter CatalogCollation is not supported on SQL Server instance '{0}' with version '{1}'. This parameter requires SQL Server 2019 (version 15) or later.
360361
Database_Create_ShouldProcessVerboseDescription = Creating the database '{0}' on the instance '{1}'.
361362
Database_Create_ShouldProcessVerboseWarning = Are you sure you want to create the database '{0}'?
362363
# This string shall not end with full stop (.) since it is used as a title of ShouldProcess messages.

0 commit comments

Comments
 (0)