c# - Key store providers cannot be set more than once (Always Encryption using Azure Function ) -
i've implemented timetriggerc# azure function run store procedure insert table encrypted using column encryption(always encrypted, azurekey vault provider)
the blocking area me function ran @ 1 time , got error again many times. success path rare case
the error faced
mscorlib: exception has been thrown target of invocation. system.data: key store providers cannot set more once.
i done investigation on occurs in line
sqlconnection.registercolumnencryptionkeystoreproviders(providers);
with in function
static void initializeazurekeyvaultprovider() { string clientid = configurationmanager.appsettings["authclientid"]; string clientsecret = configurationmanager.appsettings["authclientsecret"]; _clientcredential = new clientcredential(clientid, clientsecret); // direct provider authentication delegate sqlcolumnencryptionazurekeyvaultprovider azurekeyvaultprovider = new sqlcolumnencryptionazurekeyvaultprovider(gettoken); dictionary<string, sqlcolumnencryptionkeystoreprovider> providers = new dictionary<string, sqlcolumnencryptionkeystoreprovider>(); providers.add(sqlcolumnencryptionazurekeyvaultprovider.providername, azurekeyvaultprovider); // register provider ado.net sqlconnection.registercolumnencryptionkeystoreproviders(providers); }
when tried deeper root cause of error, like
exception has been thrown target of invocation. ---> system.invalidoperationexception : key store providers cannot set more once. @ system.data.sqlclient.sqlconnection.registercolumnencryptionkeystoreproviders(idictionary`2 customproviders)
as mentioned above used azure key vault key store provider.i registered keyvault ad , added registered application key vault (access policies).
why i'm facing abnormal behavior, one-time success , time failure?
appreciate response,
jayendran
you running initializeazurekeyvaultprovider()
inside every function call. if works first time, when initialization wasn't performed on app instance.
during next function call instance gets reused, initialization performed. call again, duplicated registration error.
to solve it, initialization in static constructor, or store flag (static bool
) whether initialized already, , skip initialization if it's true (and take care of thread safety).
C - Key Store Providers Cannot Be Set More Than Once (Always
ReplyDeleteEncryption Using Azure Function ) - >>>>> Download Now
>>>>> Download Full
C - Key Store Providers Cannot Be Set More Than Once (Always
Encryption Using Azure Function ) - >>>>> Download LINK
>>>>> Download Now
C - Key Store Providers Cannot Be Set More Than Once (Always
Encryption Using Azure Function ) - >>>>> Download Full
>>>>> Download LINK y4