【发布时间】:2018-05-04 05:19:28
【问题描述】:
我正在使用 SSMS 中的加密列功能加密现有表中的多个列。我选择生成一个 Powershell 脚本,而不是在向导中加密列,这样我就可以在稍后的时间点加密这些列。脚本如下:
# Generated by SQL Server Management Studio at 3:03 PM on 4/05/2018
Import-Module SqlServer
# Set up connection and database SMO objects
$sqlConnectionString = "Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;Packet Size=4096;Application Name=`"Microsoft SQL Server Management Studio`""
$smoDatabase = Get-SqlDatabase -ConnectionString $sqlConnectionString
# If your encryption changes involve keys in Azure Key Vault, uncomment one of the lines below in order to authenticate:
# * Prompt for a username and password:
#Add-SqlAzureAuthenticationContext -Interactive
# * Enter a Client ID, Secret, and Tenant ID:
#Add-SqlAzureAuthenticationContext -ClientID '<Client ID>' -Secret '<Secret>' -Tenant '<Tenant ID>'
# Change encryption schema
$encryptionChanges = @()
# Add changes for table [dbo].[Voucher]
$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Voucher.Code -EncryptionType Randomized -EncryptionKey "cek"
Set-SqlColumnEncryption -ColumnEncryptionSettings $encryptionChanges -InputObject $smoDatabase
但是,当我运行脚本时,我从 Set-SqlColumnEncryption cmdlet 得到以下异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an
invocation. ---> System.TypeInitializationException: The type initializer for
'Microsoft.SqlServer.Management.AlwaysEncrypted.Management.AlwaysEncryptedManagement' threw an
exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.
我也更新了 Sqlserver 模块。当然,我不必手动将 Newtonsoft.Json.dll 文件放到 SqlServer 模块目录中。有什么想法吗?
【问题讨论】:
-
我遇到了同样的问题。就像 powershell 需要对 Newtonsoft.Json 进行某种绑定重定向。我认为这最终是通过 Microsoft.Azure.KeyVault.dll 触发的,这似乎是 AlwaysEncryptedManagement 程序集的依赖项。 Newtonsoft.json 确实在同一目录中使用此 dll,但在我的情况下,它是版本 10。我放弃了版本 6.0.1,这并不能解决我的问题。
标签: powershell always-encrypted