C# SignalR - Fix Multiple Connection String Issue
Budget: ₹600 – ₹1,500 INR
I have this class from where i am getting data from store procedure
public class StatisticalRepository
{
string connectionString;
private readonly StatisticalDBContext dbContext;
public StatisticalRepository(string connectionString, StatisticalDBContext _dbContext)
{
this.connectionString = connectionString;
this.dbContext = _dbContext;
}
public async Task<List<StatsData>> GetStatsData()
{
try
{
string sqlTextList = $"EXECUTE GetStatsData";
List<StatsData> response = await dbContext.StatsDatas.FromSqlRaw(sqlTextList).ToListAsync();
// Reload the entities from the StatsDatas table
foreach (var emp in response)
{
dbContext.Entry(emp).Reload();
}
return response;
}
catch (Exception ex)
{
throw;
}
}
}
also from subscriberhub below code
SqlTableDependency<StatsData> tableDependency;
TrueHub trueHub;
public SubscribeStatsTableDependency(TrueHub trueHub)
{
this.trueHub = trueHub;
}
public void SubscribeTableDependency(string connectionString)
{
tableDependency = new SqlTableDependency<StatsData>(connectionString);
tableDependency.OnChanged += TableDependency_OnChanged;
tableDependency.OnError += TableDependency_OnError;
tableDependency.Start();
}
i am getting issue error "'A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext" you need to fix issue on localhost currently after we get rid of this we can deploy on server.
public class StatisticalRepository
{
string connectionString;
private readonly StatisticalDBContext dbContext;
public StatisticalRepository(string connectionString, StatisticalDBContext _dbContext)
{
this.connectionString = connectionString;
this.dbContext = _dbContext;
}
public async Task<List<StatsData>> GetStatsData()
{
try
{
string sqlTextList = $"EXECUTE GetStatsData";
List<StatsData> response = await dbContext.StatsDatas.FromSqlRaw(sqlTextList).ToListAsync();
// Reload the entities from the StatsDatas table
foreach (var emp in response)
{
dbContext.Entry(emp).Reload();
}
return response;
}
catch (Exception ex)
{
throw;
}
}
}
also from subscriberhub below code
SqlTableDependency<StatsData> tableDependency;
TrueHub trueHub;
public SubscribeStatsTableDependency(TrueHub trueHub)
{
this.trueHub = trueHub;
}
public void SubscribeTableDependency(string connectionString)
{
tableDependency = new SqlTableDependency<StatsData>(connectionString);
tableDependency.OnChanged += TableDependency_OnChanged;
tableDependency.OnError += TableDependency_OnError;
tableDependency.Start();
}
i am getting issue error "'A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext" you need to fix issue on localhost currently after we get rid of this we can deploy on server.