private async Task<string> getDeviceDescription(int manufacture, string serialNu
ID: 3907263 • Letter: P
Question
private async Task<string> getDeviceDescription(int manufacture, string serialNumber)
{
var output = new sqlParameter("@deviceDescription", sqlDbType.NVarChar, 255) { Direction = ParameterDirection. Output };
await Database.ExecuteSqlCommandAsync("exec storedProcedure @manufacture, @serialNumber, @deviceDescription OUT", new sqlParameter("@manufacture", manufacture), new sqlParameter("@serialNumber", serialNumber), output);
description = (string) output.Value;
return description;
}
I keep getting System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.
Explanation / Answer
According to the mentioned exception, "one more errors occurred" error most likely the problem with stored procedure query from await Database.ExecuteSqlCommandAsync("exec storedProcedure...).
and try replacing with the following method:
private async Task<string> getDeviceDescription(int manufacture, string serialNumber)
{
var output = new sqlParameter("@deviceDescription", sqlDbType.NVarChar, 255) { Direction = ParameterDirection. Output };
var queryOutput = await Database.ExecuteSqlCommandAsync("exec storedProcedure @manufacture, @serialNumber, @deviceDescription OUT", new sqlParameter("@manufacture", manufacture), new sqlParameter("@serialNumber", serialNumber), output);
Task.WhenAll(queryOutput);
description = (string) output.Value;
return description;
}
it is also asking to use 'await' even after using in method means there might be a chance of error is not only from the given method.
so if you want more details, can you please provide code in .cs file and strack trace that you are getting.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.