Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 启用列加密Azure函数应用程序v2错误_C#_Sql_Sql Server_Azure_Function - Fatal编程技术网

C# 启用列加密Azure函数应用程序v2错误

C# 启用列加密Azure函数应用程序v2错误,c#,sql,sql-server,azure,function,C#,Sql,Sql Server,Azure,Function,目前有许多Azure函数在V1上运行,并希望开始迁移到v2,但是我遇到了通过sqlstringbuilder使用enable column encryption的问题 如果我注释掉enable column encryption属性,函数将正常执行并返回加密的数据 我需要启用列加密属性,以便它返回已解密的数据 #load "Serialize.csx" #r "System.Configuration" #r "System.Data" #r "Newtonsoft.Json" using

目前有许多Azure函数在V1上运行,并希望开始迁移到v2,但是我遇到了通过sqlstringbuilder使用enable column encryption的问题

如果我注释掉enable column encryption属性,函数将正常执行并返回加密的数据

我需要启用列加密属性,以便它返回已解密的数据

#load "Serialize.csx"

#r "System.Configuration"
#r "System.Data"
#r "Newtonsoft.Json"

using System.Configuration;
//using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Net;
using Newtonsoft.Json;
using System.Text;

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Configuration;
//using Microsoft.Data.SqlClient

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{

 string connectionString = @"Data Source = #####################;

SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder(connectionString);


// THIS LINE IS CAUSING THE ERROR
connStringBuilder.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled;

connectionString = connStringBuilder.ConnectionString;



string json =  " ";


using (SqlConnection conn = new SqlConnection(connectionString))
{
     conn.Open();

     SqlCommand cmd = new SqlCommand();
     SqlDataReader dataReader;

     cmd.CommandText = "SELECT * FROM Encrypted5";
     cmd.Connection = conn;

     dataReader = cmd.ExecuteReader();

     var r = Serialize(dataReader);

     json =  JsonConvert.SerializeObject(r, Formatting.Indented); 


     conn.Close();
}


return new HttpResponseMessage(HttpStatusCode.OK) 
{
    Content = new StringContent(json, Encoding.UTF8, "application/json")
};
}

启用时产生的错误消息:

2019-11-02T21:30:29.124[错误]运行。csx29,19:错误CS1061:“SqlConnectionStringBuilder”不包含“ColumnEncryptionSetting”的定义,并且找不到接受类型为“SqlConnectionStringBuilder”的第一个参数的扩展方法“ColumnEncryptionSetting”。是否缺少using指令或程序集引用


2019-11-02T21:30:29.295[错误]运行。csx29,45:错误CS0103:名称“SqlConnectionColumnEncryptionSetting”在当前上下文中不存在

我相信您必须使用版本为4.5.1的System.Data.SqlClient,它没有设置列加密的属性:

您可以为更新的框架升级框架,也可以简单地将设置附加到连接字符串本身:

string connectionString = "Data Source=server63; Initial Catalog=Clinic; Integrated Security=true; Column Encryption Setting=enabled";
SqlConnection connection = new SqlConnection(connectionString);
另外,请检查以下文件以供进一步参考:


希望有帮助。

根据我的研究,如果我们想使用ColumnEncryptionSetting设置来启用Always Encrypted with。net内核,我们应该使用SDK。有关更多详细信息,请参阅和。 例如 我的代码

此外,还可以使用ODBC驱动程序。ODBC驱动程序支持始终加密。 比如说

 using (var connection = new OdbcConnection(
                "Driver={ODBC Driver 17 for SQL Server};;Server={server name};Trusted_Connection=yes;ColumnEncryption=Enabled;Database={DBname};"))
            {
                using (var cmd = new OdbcCommand("", connection))
                {
                    connection.Open();
                    Console.WriteLine("Connected");
                    Console.WriteLine("SSN: " + Convert.ToString(cmd.ExecuteScalar()));
                    Console.ReadLine();
                    connection.Close();
                }
            }
有关更多详细信息,请参阅


根据我的研究,如果要使用.Net Core的列加密,需要使用sdk Microsoft.Data.SqlClient。有关更多详细信息,请参阅“非常感谢!
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
</Target>
<Target Name="PostPublish" BeforeTargets="Publish">
  <Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
  <Exec Command="move $(PublishDir)\runtimes $(PublishDir)\bin" />
</Target>
 using (var connection = new OdbcConnection(
                "Driver={ODBC Driver 17 for SQL Server};;Server={server name};Trusted_Connection=yes;ColumnEncryption=Enabled;Database={DBname};"))
            {
                using (var cmd = new OdbcCommand("", connection))
                {
                    connection.Open();
                    Console.WriteLine("Connected");
                    Console.WriteLine("SSN: " + Convert.ToString(cmd.ExecuteScalar()));
                    Console.ReadLine();
                    connection.Close();
                }
            }