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

和自甴很熟 提交于 2019-12-23 09:59:52

问题


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; UID=user.name@microsoft.contoso.com; PWD=Test@pswd";
                SqlConnection conn = new SqlConnection(ConnectionString);
                conn.Open();
                Console.WriteLine("connected");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
    }

回答1:


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.



来源:https://stackoverflow.com/questions/42088766/ado-net-azure-ad-error-keyword-not-supported-authentication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!