diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs index bdca44b743..4bd75a979e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs @@ -2732,7 +2732,7 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) SqlAuthenticationProvider? authProvider = SqlAuthenticationProviderManager.GetProvider(ConnectionOptions.Authentication); if (authProvider == null && _accessTokenCallback == null) { - throw SQL.CannotFindAuthProvider(ConnectionOptions.Authentication.ToString()); + throw SQL.CannotFindAuthProvider(ConnectionOptions.Authentication); } // We will perform retries if the provider indicates an error that diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs index c2d7d26467..8f0d7fcba0 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs @@ -511,9 +511,26 @@ internal static Exception UnsupportedAuthenticationByProvider(string authenticat return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_UnsupportedAuthenticationByProvider, type, authentication)); } - internal static Exception CannotFindAuthProvider(string authentication) - { - return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindAuthProvider, authentication)); + internal static Exception CannotFindAuthProvider(SqlAuthenticationMethod authentication) + { + string authName = authentication.ToString(); + + return authentication switch + { +#pragma warning disable 0618 + SqlAuthenticationMethod.ActiveDirectoryPassword or +#pragma warning restore 0618 + SqlAuthenticationMethod.ActiveDirectoryIntegrated or + SqlAuthenticationMethod.ActiveDirectoryInteractive or + SqlAuthenticationMethod.ActiveDirectoryServicePrincipal or + SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow or + SqlAuthenticationMethod.ActiveDirectoryManagedIdentity or + SqlAuthenticationMethod.ActiveDirectoryMSI or + SqlAuthenticationMethod.ActiveDirectoryDefault or + SqlAuthenticationMethod.ActiveDirectoryWorkloadIdentity + => ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindActiveDirectoryAuthProvider, authName)), + _ => ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindAuthProvider, authName)), + }; } internal static Exception ParameterCannotBeEmpty(string paramName) diff --git a/src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs b/src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs index f06b0686a4..2cae12cb6c 100644 --- a/src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs +++ b/src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -9316,7 +9316,16 @@ internal static string SQL_CannotFindAuthProvider { return ResourceManager.GetString("SQL_CannotFindAuthProvider", resourceCulture); } } - + + /// + /// Looks up a localized string similar to Cannot find an authentication provider for '{0}'. Install the 'Microsoft.Data.SqlClient.Extensions.Azure' NuGet package (https://www.nuget.org/packages/Microsoft.Data.SqlClient.Extensions.Azure) to use Active Directory (Entra ID) authentication methods.. + /// + internal static string SQL_CannotFindActiveDirectoryAuthProvider { + get { + return ResourceManager.GetString("SQL_CannotFindActiveDirectoryAuthProvider", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to read the config section for authentication providers.. /// diff --git a/src/Microsoft.Data.SqlClient/src/Resources/Strings.resx b/src/Microsoft.Data.SqlClient/src/Resources/Strings.resx index 0c5e1006f1..0006d91c9d 100644 --- a/src/Microsoft.Data.SqlClient/src/Resources/Strings.resx +++ b/src/Microsoft.Data.SqlClient/src/Resources/Strings.resx @@ -1,4 +1,4 @@ - +