Reputation: 27
I have a .NET Framework 4.7.2 web app that is using EF6.2 (Entity Framework) on 2012R2 server, connecting to an on-prem SQL server without any issues. Now, I am trying to connect the same app to an Azure SQL MI database from an Azure VM (2019 server) and I get ADAL-related errors. A console application with an Azure AD Password connection string works fine on the same machine. Also, the EF app works fine on the 2012 server, it is the EF version app on the 2019 Azure server VMs that is having the issues. Any pointers in resolving this is really appreciated.
This is the connection string:
<add name="MyEntities" connectionString="metadata=res:///EntityFramework.XXX.csdl|res:///EntityFramework.XXXX.ssdl|res://*/EntityFramework.XXX.msl;provider=System.Data.SqlClient;provider connection string='data source=XXXX.XXXX.database.windows.net;initial catalog=testDB;persist security info=True;user [email protected];password=XXXX;authentication="Active Directory Password";MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
This is the error:
InnerException: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> AdalException: The request has timed out. at ADALNativeWrapper.ADALGetAccessToken
...
in XXXXX\source\repos\SampleEF\DataObjects\EntityFramework\XXXX.cs:line 19
Upvotes: 0
Views: 725
Reputation: 5570
This error AdalException: The request has timed out. at ADALNativeWrapper.ADALGetAccessToken" usually occurs, if access to azure ad is blocked by your firewall or expiration of access token.
To resolve this,
SET NOCOUNT ON;
SET ARITHABORT ON;
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), o => o.CommandTimeout(180)));
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{
this.Database.SetCommandTimeout(90); // <-- 90 seconds
}}
References :
c# - Entity Framework Timeouts - Stack Overflow by N-ate.
Timeout and ADALGetAccessToken Error with AAD connections - Microsoft Tech Community.
Access token expired Issue · Issue #1596 · AzureAD/azure-activedirectory-library-for-dotnet · GitHub.
Upvotes: 0