EDIT: After a lot of testing I have found that the problem had nothing to do with the OutOfMemoryException at all. Thanks for all your help, which led me to search for other reasons.
This case is closed!
I have a strange problem. My program has worked since last summer and now they updated Windows 10 to version 1709 (the computer is not usually connected)
And now I get an System.OutOfMemoryException when I try to access the database.
The table contains about 1 million rows, but since I'm using First() it shouldn't matter (should it??)
Have somebody a clue on what is wrong?
EDIT: Added the code for the context and the POCO.
EDIT 2: Added the SQL Query for context.LaserDate.First();
The database is an MS SQL Server 2014 and is accessed over the Local Network.
The code looks like this:
internal void IsConnectionOK()
{
try
{
using (var context = new DCLasermarkContext())
{
var tmp = context.LaserData.First();
}
}
catch (Exception ex)
{
Log.Fatal(ex, "IsConnection Failed!");
throw;
}
}
and the exception:
2018-04-20 07:29:37.3068 | FATAL | DCMarker.Model.DB.IsConnectionOK | IsConnection Failed! | System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Data.Entity.Core.Common.EntitySql.CqlParser.yyparse()
at System.Data.Entity.Core.Common.EntitySql.CqlParser.internalParseEntryPoint()
at System.Data.Entity.Core.Common.EntitySql.CqlParser.Parse(String query)
at System.Data.Entity.Core.Common.EntitySql.CqlQuery.Parse(String commandText, ParserOptions parserOptions)
at System.Data.Entity.Core.Common.EntitySql.CqlQuery.CompileCommon[TResult](String commandText, ParserOptions parserOptions, Func`3 compilationFunction)
at System.Data.Entity.Core.Common.EntitySql.CqlQuery.CompileQueryCommandLambda(String queryCommandText, Perspective perspective, ParserOptions parserOptions, IEnumerable`1 parameters, IEnumerable`1 variables)
at System.Data.Entity.Core.Objects.EntitySqlQueryState.Parse()
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateInlineQueryOfT(ObjectQuery inlineQuery)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.ObjectQueryMergeAsTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.ObjectQueryMergeAsTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0[TResult](IEnumerable`1 sequence)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.First[TSource](IQueryable`1 source)
at DCMarker.Model.DB.IsConnectionOK()
EDIT:
public partial class DCLasermarkContext : DbContext
{
public DCLasermarkContext()
: base("name=DCLasermarkContext")
{
// Without this line, the compiler will optimize away System.Data.Entity.SqlServer
var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
// make sure that we don't initialize the database!!
Database.SetInitializer<DCLasermarkContext>(null);
}
public virtual DbSet<Fixture> Fixture { get; set; }
public virtual DbSet<HistoryData> HistoryData { get; set; }
public virtual DbSet<LaserData> LaserData { get; set; }
public virtual DbSet<QuarterCode> QuarterCode { get; set; }
public virtual DbSet<SerialNumber> SerialNumber { get; set; }
public virtual DbSet<WeekCode> WeekCode { get; set; }
protected override System.Data.Entity.Validation.DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, System.Collections.Generic.IDictionary<object, object> items)
{
if (entityEntry.Entity is LaserData)
{
if (string.IsNullOrWhiteSpace(entityEntry.CurrentValues.GetValue<string>("F1")))
{
var list = new List<System.Data.Entity.Validation.DbValidationError>();
list.Add(new System.Data.Entity.Validation.DbValidationError("F1", GlblRes.ArticleF1_is_required));
return new System.Data.Entity.Validation.DbEntityValidationResult(entityEntry, list);
}
}
return base.ValidateEntity(entityEntry, items);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//modelBuilder.Types()
modelBuilder.Entity<Fixture>()
.Property(e => e.FixturId)
.IsUnicode(false);
modelBuilder.Entity<HistoryData>()
.Property(e => e.Kant)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<HistoryData>()
.Property(e => e.DateMark)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<HistoryData>()
.Property(e => e.DateMarkLong)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<HistoryData>()
.Property(e => e.DateMarkShort)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<LaserData>()
.Property(e => e.Kant)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<QuarterCode>()
.Property(e => e.QYear)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<QuarterCode>()
.Property(e => e.Q1)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<QuarterCode>()
.Property(e => e.Q2)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<QuarterCode>()
.Property(e => e.Q3)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<QuarterCode>()
.Property(e => e.Q4)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<WeekCode>()
.Property(e => e.Code)
.IsFixedLength()
.IsUnicode(false);
}
}
[Table("LaserData")]
public partial class LaserData
{
public int Id { get; set; }
[Required]
[StringLength(50)]
public string F1 { get; set; }
[StringLength(1)]
public string Kant { get; set; }
[StringLength(100)]
public string Avdelning { get; set; }
[StringLength(50)]
public string F2 { get; set; }
[StringLength(50)]
public string F3 { get; set; }
[StringLength(50)]
public string F4 { get; set; }
[StringLength(50)]
public string F5 { get; set; }
[StringLength(50)]
public string F6 { get; set; }
[StringLength(50)]
public string F7 { get; set; }
[StringLength(50)]
public string F8 { get; set; }
[StringLength(50)]
public string F9 { get; set; }
[StringLength(50)]
public string F10 { get; set; }
[StringLength(50)]
public string BC1 { get; set; }
[StringLength(50)]
public string BC2 { get; set; }
[StringLength(50)]
public string Template { get; set; }
[StringLength(50)]
public string P1 { get; set; }
[StringLength(50)]
public string P2 { get; set; }
[StringLength(50)]
public string P3 { get; set; }
[StringLength(50)]
public string P4 { get; set; }
[StringLength(50)]
public string P5 { get; set; }
[StringLength(50)]
public string P6 { get; set; }
[StringLength(50)]
public string FixtureId { get; set; }
public bool? ExternTest { get; set; }
public bool? EnableTO { get; set; }
[StringLength(50)]
public string TOnr { get; set; }
}
Query for context.LaserData.First()
SELECT TOP (1)
[c].[Id] AS [Id],
[c].[F1] AS [F1],
[c].[Kant] AS [Kant],
[c].[Avdelning] AS [Avdelning],
[c].[F2] AS [F2],
[c].[F3] AS [F3],
[c].[F4] AS [F4],
[c].[F5] AS [F5],
[c].[F6] AS [F6],
[c].[F7] AS [F7],
[c].[F8] AS [F8],
[c].[F9] AS [F9],
[c].[F10] AS [F10],
[c].[BC1] AS [BC1],
[c].[BC2] AS [BC2],
[c].[Template] AS [Template],
[c].[P1] AS [P1],
[c].[P2] AS [P2],
[c].[P3] AS [P3],
[c].[P4] AS [P4],
[c].[P5] AS [P5],
[c].[P6] AS [P6],
[c].[FixtureId] AS [FixtureId],
[c].[ExternTest] AS [ExternTest],
[c].[EnableTO] AS [EnableTO],
[c].[TOnr] AS [TOnr]
FROM [dbo].[LaserData] AS [c]