Fix: 'A window handle must be configured' (window_handle_required) with Authentication=Active Directory Interactive
Microsoft.Data.SqlClient 6.1.6+ and 7.x route Active Directory Interactive through the Windows WAM broker, which needs a parent window. In Azure Functions or services, switch to Active Directory Default.
This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process
Short answer: since Microsoft.Data.SqlClient 6.1.6 (and Microsoft.Data.SqlClient.Extensions.Azure 7.0.2), Authentication=Active Directory Interactive on Windows always goes through the Web Account Manager (WAM) broker when you use SqlClient’s built-in client ID, and WAM refuses to show a sign-in prompt without a parent window. Windowless processes such as an Azure Functions worker started by func start have none, so you get 0xwindow_handle_required. For local development in a windowless host, change the connection string to Authentication=Active Directory Default and sign in once with az login or Visual Studio. UseWamBroker = false only works together with your own ApplicationClientId.
That is why the failure appears “out of nowhere” after a routine package update: EF Core 10.0.10 depends on SqlClient 6.1.1, while EF Core 10.0.11 and 10.0.12 depend on 6.1.6, so a patch bump of EF Core silently turns WAM on. The rest of this post shows the exact error, the code path that produces it, a measured matrix of which provider configurations actually disable WAM, and the four fixes in order of preference.
The error in context
With EF Core, the exception surfaces on the first query or SaveChanges:
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(...)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
Nothing else happens: no browser tab opens and no account picker appears. Before the update, the same connection string opened the system browser for sign-in. On SqlClient 6.1.8, 7.0.4 and 7.1.2 the message is longer and starts with “Active Directory Interactive authentication with Windows Web Account Manager (WAM) requires a valid parent window handle”, followed by the three supported alternatives. The underlying error code is still window_handle_required. Searchers also hit it in localized form, for example the German “Fehler beim Authentifizieren des Benutzers … Fehlercodecode 0xwindow_handle_required”.
The typical setup that triggers it, taken from the Stack Overflow report that led to the upstream issue:
- Azure Functions isolated worker on .NET 10, run locally with Azure Functions Core Tools 4.x on Windows 11.
- Production uses
Authentication=Active Directory Managed Identity, local development usesAuthentication=Active Directory Interactiveso the developer signs in with their own Entra ID account. Microsoft.EntityFrameworkCore.SqlServerupdated from 10.0.10 to 10.0.11 or 10.0.12.
Why this happens
Three changes line up.
1. SqlClient added WAM support in a patch release. The 6.1.6 release notes (June 25, 2026) added the Web Account Manager broker for Entra ID authentication on Windows, a new ActiveDirectoryAuthenticationProviderOptions type with UseWamBroker, and a SetParentActivityOrWindowFunc method. The same feature shipped for the 7.x line in Microsoft.Data.SqlClient.Extensions.Azure 7.0.2, the package that holds Entra ID authentication since SqlClient 7 split it out.
2. WAM is forced for SqlClient’s built-in client ID. When you do not pass your own Entra ID application, SqlClient authenticates as its own first-party Microsoft application. The constructor in ActiveDirectoryAuthenticationProvider.cs at v6.1.8 reads:
// Microsoft.Data.SqlClient 6.1.8, ActiveDirectoryAuthenticationProvider.cs (excerpt)
_useWamBroker = _applicationClientId == ActiveDirectoryAuthentication.AdoClientId || options.UseWamBroker;
So UseWamBroker = false is ignored unless ApplicationClientId points at a different app. A SqlClient maintainer explained in dotnet/SqlClient#4854 that routing through WAM on platforms where it is available is a requirement of that first-party app, and that headless environments should use a non-interactive mode instead.
3. The parent window comes from the console. On Windows, MSAL needs a window handle to parent the WAM dialog. Unless you supply one, SqlClient’s GetParentWindow() falls back to GetConsoleWindow() and returns IntPtr.Zero when there is no console:
// Microsoft.Data.SqlClient 6.1.6, ActiveDirectoryAuthenticationProvider.Windows.cs (excerpt)
IntPtr consoleHandle = Kernel32.GetConsoleWindow();
if (consoleHandle != IntPtr.Zero)
{
IntPtr rootOwner = User32.GetRootOwner(consoleHandle);
return rootOwner != IntPtr.Zero ? rootOwner : consoleHandle;
}
return IntPtr.Zero;
According to the analysis in the upstream issue, the Functions host starts the isolated worker process without a console window of its own, even though func start itself runs in a terminal. The worker gets NULL, MSAL gets a zero handle, and WAM fails with window_handle_required. The same happens in any process without a console window: Windows services, IIS app pools, scheduled tasks, and test hosts launched without a console.
Which package versions are affected
| Package | Version | Interactive auth on Windows |
|---|---|---|
Microsoft.Data.SqlClient | 6.1.5 and older | System browser, no WAM |
Microsoft.Data.SqlClient | 6.1.6, 6.1.7 | WAM, short MSAL error |
Microsoft.Data.SqlClient | 6.1.8 | WAM, longer error with guidance |
Microsoft.Data.SqlClient.Extensions.Azure | 7.0.2, 7.0.3, 7.1.0, 7.1.1 | WAM, short MSAL error |
Microsoft.Data.SqlClient.Extensions.Azure | 7.0.4, 7.1.2 | WAM, longer error with guidance |
And how EF Core pulls them in, read from each package’s nuspec on nuget.org:
Microsoft.EntityFrameworkCore.SqlServer | Microsoft.Data.SqlClient dependency |
|---|---|
| 10.0.10 | 6.1.1 |
| 10.0.11, 10.0.12 | 6.1.6 |
| 10.0.13, 10.0.14, 10.0.15 | 6.1.7 |
| 11.0.0 | 7.1.1 |
The 6.1.8 and 7.0.4/7.1.2 changes (#4858, cherry-picked in #4918) only improve the error text. Their release notes say it plainly: WAM remains enforced for the first-party application ID and no automatic fallback was added. Upgrading SqlClient does not make the error go away.
Minimal repro
// Azure Functions isolated worker, .NET 10, Microsoft.EntityFrameworkCore.SqlServer 10.0.12
// (pulls in Microsoft.Data.SqlClient 6.1.6). Run on Windows with `func start`.
// local.settings.json:
// "ConnectionStrings": {
// "Sql": "Server=myserver.database.windows.net;Database=mydb;Authentication=Active Directory Interactive;Encrypt=True"
// }
var builder = FunctionsApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDb>(o =>
o.UseSqlServer(builder.Configuration.GetConnectionString("Sql")));
builder.Build().Run();
// Any function that touches AppDb fails on the first query with 0xwindow_handle_required.
The same project works with EF Core 10.0.10, and it works on macOS and Linux with every version, because UseWamBroker has no effect off Windows and interactive sign-in there always uses the system browser.
What actually turns WAM off: a measured matrix
The comments on the upstream issue show the most common wrong turn: setting UseWamBroker = false and nothing else. To pin down exactly which configurations disable WAM, a small file-based app constructed each provider variant and read the provider’s private _useWamBroker field via reflection. The field is computed in the constructor on every OS, so the check does not need Windows. It ran on macOS with SDK 10.0.302 against Microsoft.Data.SqlClient 6.1.6 and 6.1.8, and against Microsoft.Data.SqlClient 7.1.2 with Microsoft.Data.SqlClient.Extensions.Azure 7.1.2:
// .NET 10 file-based app: dotnet run probe.cs
#:package Microsoft.Data.SqlClient@6.1.8
#:property PublishAot=false
using System.Reflection;
using Microsoft.Data.SqlClient;
static bool Wam(ActiveDirectoryAuthenticationProvider p) =>
(bool)typeof(ActiveDirectoryAuthenticationProvider)
.GetField("_useWamBroker", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(p)!;
const string own = "00000000-0000-0000-0000-000000000001";
Console.WriteLine(Wam(new()));
Console.WriteLine(Wam(new(new ActiveDirectoryAuthenticationProviderOptions { UseWamBroker = false })));
Console.WriteLine(Wam(new(new ActiveDirectoryAuthenticationProviderOptions { ApplicationClientId = own, UseWamBroker = false })));
Console.WriteLine(Wam(new(new ActiveDirectoryAuthenticationProviderOptions { ApplicationClientId = own })));
Console.WriteLine(Wam(new(own)));
var registered = SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive);
Console.WriteLine(Wam((ActiveDirectoryAuthenticationProvider)registered!));
Results were identical on all three versions (the snippet above is the exact 6.1.8 run; the 7.1.2 run adds #:package Microsoft.Data.SqlClient.Extensions.Azure@7.1.2):
| Provider configuration | WAM enabled |
|---|---|
new ActiveDirectoryAuthenticationProvider() | True |
Options { UseWamBroker = false } | True |
Options { ApplicationClientId = own, UseWamBroker = false } | False |
Options { ApplicationClientId = own } | False |
new ActiveDirectoryAuthenticationProvider(own) | False |
Provider registered by default for ActiveDirectoryInteractive | True |
Two things follow. UseWamBroker = false alone is a no-op. And WAM is opt-in, not opt-out, for your own application ID: passing ApplicationClientId is what disables it. This check does not exercise a real Windows sign-in; the Windows-side behavior comes from the SqlClient source and the upstream issue.
Fix, in detail
Fix 1 (recommended): use Active Directory Default for local development
Active Directory Default wraps Azure.Identity’s DefaultAzureCredential (SqlClient forces ExcludeInteractiveBrowserCredential = true), which picks up the account you are already signed in with in Azure CLI, Azure Developer CLI, Azure PowerShell, or Visual Studio. No window is needed, so it works in the Functions worker.
// local.settings.json, Azure Functions Core Tools 4.x
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"ConnectionStrings": {
"Sql": "Server=myserver.database.windows.net;Database=mydb;Authentication=Active Directory Default;Encrypt=True"
}
}
Then sign in once from a terminal:
az login
Make sure the signed-in account is a database user (CREATE USER [you@contoso.com] FROM EXTERNAL PROVIDER;), exactly as it had to be for interactive sign-in. If you belong to several tenants, add --tenant <tenant-id> to az login, or set AZURE_TENANT_ID in Values.
You can keep Active Directory Managed Identity in production, or use Active Directory Default there too, since DefaultAzureCredential also tries managed identity. Explicit Managed Identity in production avoids walking the credential chain on a cold start, so many teams keep the two connection strings separate.
Fix 2: bring your own app registration and disable WAM
If you really want a browser prompt from a windowless process, register a public client application in Entra ID and hand SqlClient its client ID with WAM turned off. This is the workaround the issue reporter documented:
// .NET 10, Microsoft.Data.SqlClient 6.1.6+ (or Extensions.Azure 7.0.2+ on SqlClient 7).
// Run once at startup, before the first connection opens.
using Microsoft.Data.SqlClient;
var provider = new ActiveDirectoryAuthenticationProvider(new ActiveDirectoryAuthenticationProviderOptions
{
ApplicationClientId = "<your app (client) id>",
UseWamBroker = false,
});
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
The app registration needs:
- Platform: “Mobile and desktop applications” with redirect URI
http://localhost. On .NET (not .NET Framework) without WAM, SqlClient uses MSAL’s system browser flow with exactly that loopback redirect. - API permissions: Azure SQL Database (find it under “APIs my organization uses”), delegated permission
user_impersonation, with consent granted.
Guard the call with an environment check (for example builder.Environment.IsDevelopment()) so production keeps managed identity. On SqlClient 7.x the provider type lives in Microsoft.Data.SqlClient.Extensions.Azure but keeps the Microsoft.Data.SqlClient namespace, so the same code compiles once that package is referenced.
Fix 3: give WAM a real window, if your app has one
Desktop apps that own a window can keep WAM, with its single sign-on, Windows Hello, and Conditional Access support, by supplying the handle. SetParentActivityOrWindowFunc was added in 6.1.6 and expects an IntPtr on Windows:
// .NET 10 WPF, Microsoft.Data.SqlClient 6.1.6+
using System.Windows;
using System.Windows.Interop;
using Microsoft.Data.SqlClient;
var provider = new ActiveDirectoryAuthenticationProvider();
provider.SetParentActivityOrWindowFunc(() =>
new WindowInteropHelper(Application.Current.MainWindow).Handle);
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
For WinForms, return mainForm.Handle. This matters beyond Functions: a WPF or WinForms app on .NET has no console window either, so the console fallback inside SqlClient finds nothing and the default provider is expected to fail the same way (inferred from the source above, not reproduced here). The callback runs when MSAL builds the client, so return a window that exists by the time the first connection opens. This does not help a Functions worker or a service; there is no window to return.
Fix 4 (stopgap): pin the previous SqlClient
If you cannot change the connection string today, pin Microsoft.Data.SqlClient to 6.1.5 in the project (or in Directory.Packages.props with transitive pinning) so the browser flow comes back. EF Core 10.0.11 and later declare 6.1.6 or higher as a minimum, so the downgrade fails restore (checked with Microsoft.EntityFrameworkCore.SqlServer 10.0.12 on SDK 10.0.302: error NU1605: Warning As Error: Detected package downgrade: Microsoft.Data.SqlClient from 6.1.6 to 6.1.5) and you would have to suppress it. 6.1.6 also carried a TDS parsing hardening fix and dependency security updates. Treat this as a one-day bridge, not a fix.
A reflection or UnsafeAccessor write to the private _useWamBroker field also works, and is posted in the issue thread. It depends on a private field name, bypasses a requirement of the first-party app, and can break on any patch release. Do not ship it.
Gotchas and variants
- macOS and Linux colleagues cannot reproduce it. WAM is Windows-only. Their interactive sign-in still opens the system browser on every version.
Active Directory Defaultfails withCredentialUnavailableException. Nothing in the chain had a signed-in account. Runaz login(or sign in under Tools > Options > Azure Service Authentication in Visual Studio) in the same Windows user session that runsfunc start.- SqlClient 7 says the authentication method is not supported after an EF Core 11 upgrade. That is a different problem: Entra ID authentication moved to the
Microsoft.Data.SqlClient.Extensions.Azurepackage in SqlClient 7. Reference it, and see the SqlClient 7.0.0.0 load error post for the assembly side of the same upgrade. - Other authentication modes.
Active Directory Default,Managed IdentityandService Principalnever show UI, so they have no use for a parent window. SqlClient’swindow_handle_requiredmessage translation is wired only toActiveDirectoryInteractive.
Related
- Microsoft.Data.SqlClient vs System.Data.SqlClient in .NET 11 covers the 7.x package split that moved Entra ID auth into Extensions.Azure.
- Fix NU1903 for System.Security.Cryptography.Pkcs pulled in by Microsoft.Data.SqlClient is the other SqlClient patch-bump surprise of the 6.1.x line.
- Azure Functions isolated worker vs in-process in .NET 11 explains why your code runs in a separate worker process at all.
- Fix: No connection string named ‘DefaultConnection’ could be found helps when
local.settings.jsonconnection strings are not picked up.
Sources
- dotnet/SqlClient#4854: WAM broker integration breaks windowless uses, including the maintainer’s explanation of the first-party app requirement.
- dotnet/SqlClient#4858: Improve WAM authentication diagnostics for windowless hosts.
- Microsoft.Data.SqlClient 6.1.6 release notes and 6.1.8 release notes.
- Microsoft.Data.SqlClient.Extensions.Azure 7.0.2 release notes.
ActiveDirectoryAuthenticationProvider.Windows.csat v6.1.6.- MSAL.NET: using the Web Account Manager broker.
- Stack Overflow: Debugging Azure Function does not work after upgrading Microsoft.EntityFrameworkCore from 10.0.10 to 10.0.11/12.
Comments
Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.