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();
}
}
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 theSqlConnection
class. To take advantage of AAD authentication, download version 4.6 of theSystem.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 theMicrosoft.IdentityModel.Clients.ActiveDirectory
NuGet package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With