Share via

powershell command Add-SqlAzureAuthenticationContext -Interactive throws an exception

Al2020s 101 Reputation points
2021-05-20T22:36:53.823+00:00

Add-SqlAzureAuthenticationContext : The type initializer for
'Microsoft.SqlServer.Management.AlwaysEncrypted.Types.AlwaysEncryptedManager' threw an exception.
At line:1 char:1

  • Add-SqlAzureAuthenticationContext -Interactive
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidArgument: (:) [Add-SqlAzureAuthenticationContext], TypeInitializationException
  • FullyQualifiedErrorId : AzureAuthError,Microsoft.SqlServer.Management.PowerShell.AlwaysEncrypted.AddSqlAzureAuth
    enticationContext
Azure SQL Database
0 comments No comments

Answer accepted by question author

Al2020s 101 Reputation points
2021-05-22T21:24:28.44+00:00

I found the problem: .NET 4.7.0.02053. After upgrading to v 4.7.03062 I was able to authenticate to Azure via PowerShell

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Al2020s 101 Reputation points
    2021-05-20T23:13:09.083+00:00

    .NET installed: 4.7.0.02053 as well v2 and 3

    Was this answer helpful?

    0 comments No comments

  2. Al2020s 101 Reputation points
    2021-05-20T23:07:13.587+00:00

    Was this answer helpful?

    0 comments No comments

  3. Al2020s 101 Reputation points
    2021-05-20T23:04:13.657+00:00

    Yes, I am running PS in admin mode:
    PS version 5.1.14393.4402
    SqlServer Module version 21.1.18245

    Commands which were entered:

    Import-Module "SqlServer"

    $CmkSettings = New-SqlCertificateStoreColumnMasterKeySettings -CertificateStoreLocation -KeyUrl “https://kv-busa01.vault.azure.net:443/keys/CMK002/cd4d8430d9ca445593b7d96e19d56e17”

    Add-SqlAzureAuthenticationContext -Interactive

    Was this answer helpful?

    0 comments No comments

  4. Marilee Turscak-MSFT 37,396 Reputation points Microsoft Employee Moderator
    2021-05-20T22:54:07.893+00:00

    Please verify that you have the right version of the .NET framework installed and that you've imported the SqlServer module (running as administrator)

    Import-Module "SqlServer"
    

    It could also be that there are some dependencies or files not loading when using 'Microsoft.SqlServer.Management.AlwaysEncrypted.Types.AlwaysEncryptedManager'

    If so, it would be helpful if you shared the code that you used to configure "always encrypted."

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.