Currently have a number of Azure Functions running on V1 and looking to start to migrate to v2 however i'm running into issues with enable column encryption using via the sqlstringbuilder.
If i comment out the enable column encryption property the function executes fine and returns data that is encrypted.
I need to enable the column encryption property so that it return data that is decrypted.
#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")
};
}
Resulting Error Messages when enable:
2019-11-02T21:30:29.124 [Error] run.csx(29,19): error CS1061: 'SqlConnectionStringBuilder' does not contain a definition for 'ColumnEncryptionSetting' and no extension method 'ColumnEncryptionSetting' accepting a first argument of type 'SqlConnectionStringBuilder' could be found (are you missing a using directive or an assembly reference?)
2019-11-02T21:30:29.295 [Error] run.csx(29,45): error CS0103: The name 'SqlConnectionColumnEncryptionSetting' does not exist in the current context