I'm having a problem using SQL Server Always Encrypted with Azure Sql Databases. I have an Azure Key Vault set up and the powershell script to create the CMK executes without error. The powershell script to create the CEK fails when executing the cmdlet 'New-SqlColumnEncryptionKey'.
The error output is:
One or more errors occurred.
An Error Occurred
New-SqlColumnEncryptionKey : One or more errors occurred.
At C:\users\<username>\desktop\2-GenerateColumnKeys.ps1:87 char:4
+ New-SqlColumnEncryptionKey -Name $cekName -InputObject $d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SqlColumnEncryptionKey], AggregateException
+ FullyQualifiedErrorId : ReflectionError,Microsoft.SqlServer.Management.PowerShell.AlwaysEncrypted.NewSqlColumnEn
cryptionKey
Script/Steps for Reproduction
The following script fails the first time you run it. If you run it again in the same powershell window, it will execute successfully. We're using VSTS to orchestrate the execution of this script so it needs to run first time.
I have also created an Azure VM with Windows Server 2016 on it, installed sql-server module and ran the script. The same error occurred
DEBUG: (New-SqlColumnEncryptionKey) In method ProcessRecord. Resolving targets.
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): A
DEBUG: (New-SqlColumnEncryptionKey) Resolving targets: Parameter Set = 'ByObject'
DEBUG: (New-SqlColumnEncryptionKey) Resolved target [<database name>]
DEBUG: (New-SqlColumnEncryptionKey) GetShouldProcessTargetString in SqlCmdlet.
DEBUG: (New-SqlColumnEncryptionKey) Validating Target
DEBUG: (New-SqlColumnEncryptionKey) ValidateTarget in SqlCmdlet. Returning true.
DEBUG: (New-SqlColumnEncryptionKey) Target is valid. Calling BeginTargetProcessing.
DEBUG: (New-SqlColumnEncryptionKey) In BeginTargetProcessing
DEBUG: (New-SqlColumnEncryptionKey) Subscribing to server events: InfoMesage, StatementExecuted
DEBUG: (New-SqlColumnEncryptionKey) Done with BeginTargetProcessing. Calling ProcessTarget.
DEBUG: (New-SqlColumnEncryptionKey) Initializing object: Type =
'Microsoft.SqlServer.Management.Smo.ColumnEncryptionKey', Name = 'CEK'
DEBUG: (New-SqlColumnEncryptionKey) Exception occurred System.Management.Automation.PipelineStoppedException: The
pipeline has been stopped.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
at System.Management.Automation.Cmdlet.ThrowTerminatingError(ErrorRecord errorRecord)
at Microsoft.SqlServer.Management.PowerShell.AlwaysEncrypted.NewSqlColumnEncryptionKey.InitializeObject(Database
db)
at Microsoft.SqlServer.Management.PowerShell.SmoCreateCmdlet`2.ProcessTarget(SmoRecordContext target)
at Microsoft.SqlServer.Management.PowerShell.SqlCmdlet`1.ProcessRecord()
DEBUG: (New-SqlColumnEncryptionKey) Calling EndProcessing.
DEBUG: (New-SqlColumnEncryptionKey) In EndTargetProcessing
DEBUG: (New-SqlColumnEncryptionKey) Unsubscribing from server events: InfoMesage, StatementExecuted
New-SqlColumnEncryptionKey : One or more errors occurred.
At C:\users\<username>\desktop\2-GenerateColumnKeys.ps1:87 char:4
+ New-SqlColumnEncryptionKey -Name $cekName -InputObject $d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SqlColumnEncryptionKey], AggregateException
+ FullyQualifiedErrorId : ReflectionError,Microsoft.SqlServer.Management.PowerShell.AlwaysEncrypted.NewSqlColumnEn
cryptionKey
Description
I'm having a problem using SQL Server Always Encrypted with Azure Sql Databases. I have an Azure Key Vault set up and the powershell script to create the CMK executes without error. The powershell script to create the CEK fails when executing the cmdlet 'New-SqlColumnEncryptionKey'.
The error output is:
Script/Steps for Reproduction
The following script fails the first time you run it. If you run it again in the same powershell window, it will execute successfully. We're using VSTS to orchestrate the execution of this script so it needs to run first time.
I have also created an Azure VM with Windows Server 2016 on it, installed sql-server module and ran the script. The same error occurred
Workaround
Current workaround it to put a try catch block round the cmdlet and repeat the step:
Module Version
Environment Data
Debug Output