I have a huge dataset that I'm trying to execute but I'm experiencing the following error;
Statement(s) could not be prepared.
Stack Trace
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at Microsoft.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at Microsoft.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SalesForceReportSVC.Controllers.SalesForceDataLoaderController.<GetSDL>d__6.MoveNext() in C:\Users\JNyingi\source\repos\SalesForceReportSVC\SalesForceReportSVC\Controllers\SalesForceDataLoaderController.cs:line 60
The exception is thrown at the following statement
IQueryable<SalesForceProductionReportDto> dLProductions = this.repo_.salesforceLoader.FindAll();
IEnumerable<SalesForceProductionReportDto> reportDtos = dLProductions.ToList();
Repository
public IQueryable<SalesForceProductionReportDto> FindAll()
{
return this.salesForceReport.Set<SalesForceProductionReportDto>().AsNoTracking();
}
Context
private void ConfigureAPIIntegrations(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(this.APIdb, opt => opt.CommandTimeout((int)TimeSpan.FromMinutes(20).TotalSeconds));
optionsBuilder.EnableDetailedErrors();
}
I want the ToList
to implement and load data from the database.
EDIT
Even a simple Linq Query like this;
List<SalesForceProductionReportDto> salesForces = this.salesForceReport.productionReports.Select(x => x).ToList();
Takes a lot of time to execute yet I can execute a SELECT
statement for 15000 plus records in less than 1 sec.
EDIT 2
I'm selecting from a view as shown in Context
public virtual DbSet<SalesForceProductionReportDto> productionReports { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SalesForceProductionReportDto>().HasNoKey() .ToView("DailyProductionReport_Vw");
base.OnModelCreating(modelBuilder);
}
.Select(x => x)
? – Jeremy Lakeman Mar 17 '20 at 6:00