Reputation: 111
For some reason Azure SQL does not seem to be picking with my MultipleActiveResultSets=True in the connection string of my dotnet core app.
my apps connection string looks like this
Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=True;Encrypt=True;"
I still keep getting this error
A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
All my code has awaits when using async methods so I have no idea what else to do because this code works with local sql.
I am using DI with my DbContext and adding the service like this
services.AddDbContext<Models.Database.DBContext>();
Any help would be greatly appreciated.
The problem was in my Startup.cs. I missed it. OnTokenValidated had a method which was calling dbcontext but i never awaited the result. Didn't see any errors from the IDE cause normally it will warn you about not awaiting an async method. Updated the method with an await and added OnTokenValidated = async context. All fine now.
Upvotes: 0
Views: 2567
Reputation: 89361
This
A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
Is an EF error, not a SQL Server error. So MultipleActiveResultSets
is irrelevant.
All my code has awaits when using async methods . . .I am using DI with my DbContext
So probably your DI is allowing a DbContext instance to be shared between requests.
Upvotes: 1