Repository navigation
Description
Based on this question on Stack Overflow: https://stackoverflow.com/questions/80009713
When used with Authentication=Active Directory Interactive from Azure Functions local emulator on Windows OS, WAM broker integration in SqlClient fails because it uses an invalid window handle.
The Azure Functions emulator host seems to spawn processes without a console window (i.e. kernel32.dll GetConsoleWindow() returns NULL) and so I think this branch in ActiveDirectoryAuthenticationProvider is taken which causes WAM to fail.
I'd expect the SqlClient to either:
- Not use the WAM broker if it cannot acquire a window handle. I guess this would make sense for backcompat reasons since WAM integration was introduced as patch update.
- Throw an informative exception, letting the user know what steps they can take to resolve the issue. The current exception links to MSAL documentation where it's unclear how to resolve the issue in context of SqlClient - https://aka.ms/msal-net-wam#parent-window-handles
Currently, the exception looks like this:
Microsoft.Data.SqlClient.SqlException (0x80131904): Failed to authenticate the user in Active Directory (Authentication=ActiveDirectoryInteractive).
Error code 0xwindow_handle_required
A window handle must be configured. See https://aka.ms/msal-net-wam#parent-window-handles
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, TimeoutTimer timeout, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, IDbConnectionPool pool, Func`3 accessTokenCallback)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionPoolGroupProviderInfo poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(IDbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at AzureFunctionWithEfCore.HttpTriggerCSharp.Run(HttpRequest unused) in C:\Projects\AzureFunctionWithEfCore\HttpTriggerCSharp.cs:line 15
ClientConnectionId:8fad0be6-d01f-4a9c-8dc0-074d339981e9
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Oct 16, 2026
🔍 Triage Summary
Area\Azure ConnectivityAnalysis
With
Authentication=Active Directory Interactive, the WAM broker path inActiveDirectoryAuthenticationProvider.Windows.csappears to use the console window handle, which isNULLin windowless hosts such as the Azure Functions local emulator. MSAL then fails with an invalid parent window handle error. Severity is probably P2: it affects a specific hosting scenario, but it is a regression-prone behavior and the error message is not actionable.Next Steps
ActiveDirectoryAuthenticationProvider.Windows.cs. It should skip the WAM broker, or fall back to the non-broker interactive flow, when no valid window handle is available. Failing that, it should throw an exception explaining how to resolve it in a SqlClient context.Active Directory Interactiveauthentication opens non-browser window after 60+ second delay (worked in 7.0.1) #4414 for related interactive-auth behavior changes.ErikEJ commentedon Oct 16, 2026
@zdenek-jelinek Is there a workaround ??
zdenek-jelinek commentedon Oct 16, 2026
The 6.1.6 release notes include a snippet that can be adapted to disable WAM:
EDIT:
The above is not sufficient. WAM stays enabled even with the above configuration unless
ApplicationClientIdis provided. Unfortunately, I have no idea what that should be when running Azure Functions locally.Would be nice to throw an exception here instead of ignoring the provided configuration.
zdenek-jelinek commentedon Oct 16, 2026
To make this work without WAM, it's necessary to:
http://localhostas the value.Application (client) IDfrom there and add it to the options in the code snippet above.Database access from the Function should now open a browser window and ask for authentication.
ErikEJ commentedon Oct 16, 2026
@zdenek-jelinek Thanks, that is ridiculous!
mdaigle commentedon Oct 16, 2026
Hey @zdenek-jelinek, sorry you're facing this issue.
To provide some background, the default Entra Id application id used in the driver is a Microsoft first-party Entra Id app. First party apps are owned and maintained by Microsoft and are subject to increased scrutiny and security requirements. In this case, it was a requirement for the First party app that connections go through WAM on platforms on which it's available. We provide the first party app primarily to make local development easier, so that you don't have to go through the application registrations steps described above every time you want to test something out. When developing a production application or service, we recommend that you do create your own Entra Id application so that you have full control over its settings.
Unfortunately, as you've identified, WAM does require a valid parent window handle to display the interactive auth pop up. For that reason, you should use non-interactive authentication modes (such as Active Directory Default) in headless environments.
I agree that we should wrap the exception and include a message to use non-interactive auth when a window handle can't be found.
zdenek-jelinek commentedon Oct 17, 2026
Thanks for your reply.
This makes total sense to me.
The issue is that the headless environment looks like this:

Anyway, SqlClient telling the user they should not use interactive login would definitely be an improvement here.
zdenek-jelinek commentedon Oct 17, 2026
I guess this is not my problem but I don't think you'll be able to enforce this anyway.
It's currently possible to revert to the legacy browser approach on Windows by overwriting
ActiveDirectoryAuthenticationProvider._useWamBrokerwith reflection/unsafe accessor:Bump Microsoft.Data.SqlClient from 6.1.1 to 6.1.8 (#104)