Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

System.InvalidOperationException: The connection does not support MultipleActiveResultSets.

14.05.2018 (👁15551)


 

 

Error message:

fail: Microsoft.EntityFrameworkCore.Update[10000]

      An exception occurred in the database while saving changes for context type 'Readdy.Data.ApplicationDbContext'.

      Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.InvalidOperationException: The connection does not support MultipleActiveResultSets.

         at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__108_0(Task`1 result)

         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()

         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)

 

 

What to try

1.Lösungs test:

You have to set the parameter MultipleActiveResultSets to true for the SQL Server Connectionstring ...

Connection String:

public static string Connectionstring = "Data Source=.\\SQLEXPRESS;Initial Catalog=readdy;Integrated Security=True;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=false;MultipleActiveResultSets=True";   

 

 

 

2.Lösungs test:

All read connections to SQL Server with await .. Build async

        try

        {

            //*get User Summary Table

            User_SumModel summary = new User_SumModel();

 

            //< with dbContext >

            summary = await Database.EF_Model.dbContext.tbl_User_Sums.FirstOrDefaultAsync(u => u.IDUser == IDUser);

            //</ with dbContext >

 

            //--< Increment SumCounter >--

            if (summary == null)

            {

                summary = new User_SumModel();

                summary.SumViews_Self = 1;

                summary.IDUser = IDUser;

                summary.dtStart = DateTime.Now;

                summary.dtEnd = DateTime.Now;

                Database.EF_Model.dbContext.tbl_User_Sums.Add(summary);

               

            }

            else

            {

                summary.SumViews_Self += 1;

                summary.dtEnd = DateTime.Now;

            }

 

           

            await Database.EF_Model.dbContext.SaveChangesAsync(true);

            //--</ Increment SumCounter >--

 

        }

        finally

        {

 

        }

 

Part 2

Rewriting of synchronous code in asynchronous

var qResult= await query.FirstOrDefaultAsync();

sText = qResult.n.Title;

IDNote0 = qResult.n.IDNote;

 

//IDNote0 = query.FirstOrDefault().n.IDNote;

sImage = "https://Readdy.net/User_Files/Notes/Images/Image_" + IDNote0 + "_0.jpg";

 

3.Lösungs test:

All write connections to SQL Server WITHOUT await .. Build async!