Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.Net (Azure AD) error "keyword not supported : authentication "

Tags:

ado.net

c#-4.0

I am trying to connect to Azure db with Azure AD credentials through c# code (Code is below). It works fine on my system. But when I deploy it to a 32 bit VM, it shows error

"Keyword not supported : authentication".

The VM has .Net framework 4.5 installed (But not Visual Studio). Application is targeting .Net Framework 4.5.

As per my observations, system.data for framework 2.0 does not support authentication keyword for SQLConnection class. But my application is targetting 4.5 , so it should work fine with 4.5 installed. can anyone help to resolve it. Below is my code

class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string ConnectionString =
      @"Data Source=mydatabase.database.windows.net; Authentication=Active Directory Password; [email protected]; PWD=Test@pswd";
                SqlConnection conn = new SqlConnection(ConnectionString);
                conn.Open();
                Console.WriteLine("connected");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
    }
like image 842
Vineet Kumar Avatar asked Feb 07 '17 11:02

Vineet Kumar


1 Answers

This answer is regarding dotnet core and not .NET Framework 4.5/6, so it does not directly answer your question. However, it may help you with respect to deployment of code to your customers.

I encountered the same error attempting to connect from dotnet-core. From Microsoft:

Starting with .NET Core 2.2, an access token issued by Azure Active Directory can be used to authenticate to an Azure SQL database. To support access tokens, the AccessToken property has been added to the SqlConnection class. To take advantage of AAD authentication, download version 4.6 of the System.Data.SqlClient NuGet package. In order to use the feature, you can obtain the access token value using the Active Directory Authentication Library for .NET contained in the Microsoft.IdentityModel.Clients.ActiveDirectory NuGet package.

like image 128
Eric Patrick Avatar answered Nov 15 '22 11:11

Eric Patrick