Hi Mark, thanks for the detailed breakdown—you're definitely on the right track. Since you're able to connect via SSMS using Microsoft Entra Integrated or Password authentication, but your app fails using SqlConnect()
with ActiveDirectoryIntegrated, the issue likely stems from one of the following:
🔍 Key Areas to Check
✅ 1. Authentication Method Compatibility
- ActiveDirectoryIntegrated requires:
- The app to run under a domain-joined Windows account.
- Azure AD joined or hybrid joined machine.
- SSO (Single Sign-On) to be enabled.
- If your machine is not domain-joined or not Azure AD joined, this method will fail silently.
- Azure AD joined or hybrid joined machine.
- The app to run under a domain-joined Windows account.
Try switching to:
Authentication = SqlAuthenticationMethod.ActiveDirectoryPassword
and explicitly provide UserID
and Password
.
✅ 2. Connection String Format
Make sure your connection string is correctly formatted. Here's a working example using ActiveDirectoryPassword:
var builder = new SqlConnectionStringBuilder
{
DataSource = "estimator1.database.windows.net",
InitialCatalog = "dbEstimator",
UserID = "******@yourdomain.com",
Password = "yourpassword",
Authentication = SqlAuthenticationMethod.ActiveDirectoryPassword,
Encrypt = true,
TrustServerCertificate = false
};
✅ 3. Error Handling
To get the actual error message, wrap your connection logic in a try-catch
block:
try
{
using var connection = new SqlConnection(builder.ConnectionString);
await connection.OpenAsync();
Console.WriteLine("Connection successful!");
}
catch (SqlException ex)
{
Console.WriteLine($"SQL Error: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"General Error: {ex.Message}");
}
✅ 4. DoSGuard Protection
If you've had multiple failed login attempts, DoSGuard may temporarily block your IP. You can:
- Wait ~15–30 minutes and retry.
- Try from a different network or IP.
- Check Azure SQL logs for blocked IPs.
✅ 5. Firewall and Network Rules
Even though SMSS works, double-check:
- Azure SQL firewall rules allow your public IP.
- No NSG or local firewall is blocking outbound traffic from your app.