powershell - Set-SqlColumnEncryption 抛出错误
问题描述
我正在使用 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 模块目录中。有任何想法吗?
解决方案
我遇到了完全相同的问题,我相信这是您特定的 OS 和 Sql Server 组合上的某种组件集成问题。
举个例子,当我试图在我的笔记本电脑上运行那个 powershell 脚本时,我收到了这个错误。我的笔记本电脑恰好使用 Windows 10 和 Sql Server Management Studio 17.2(最终生成 ps1)。此外,我的笔记本电脑确实在正确的目录中包含 Newtonsoft.Json.dll。
但是,我跳到了使用 Windows 2012 R2 和 SSMS 17.2 的服务器上,并且脚本可以正常工作!
最终,就好像在 Windows10/SSMS17.2 安装中缺少某种程序集绑定重定向,Windows2012R2/SSMS17.2 似乎可以正确解决。
推荐阅读
- sql - 如何使用 SQL 查询获得不同的结果
- reactjs - 更改语义 UI 按钮组件中的文本颜色
- sqlite - 我如何解决 sqlite 数据库 E/SQLiteLog(16449) 中的这种错误:(1) “Order”附近:语法错误
- python - 是否可以在 python 的 if 语句中将一个变量与其他几个变量进行比较?
- javascript - 为什么 array.push() 不改变数组?
- actions-on-google - 缺少用于在新的 Actions SDK 上进行交易的 conversationId
- regex - 正则表达式 - 如果被方括号包围,则删除数字
- common-lisp - CLOS 等价于析构函数
- amazon-web-services - AWS:使用 boto3 将连接添加到粘合作业
- java - flysaucer/itext - 是否可以在每个 PDF 页面上都有表头