System.OutOfMemoryException thrown on Open()

System.OutOfMemoryException thrown on Open()

Postby stephen.black » Fri 06 Jan 2017 11:18

Hello,

Firstly the system has plenty of memory and my application, developed using wpf, prism and unity is using no where nears its allowance usage is around 250-300MBS.

I am seeing System.OutOfMemoryException being thrown from Devart.Data.SQLite.SQLiteConnection.Open(). This is intermitent but it is alway the same place, Stack traces is below, Any help is greatly appreciated.

Error Messages: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegateInternal(Delegate d)
at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(Delegate d)
at Devart.Data.SQLite.bw.sqlite3_create_function(IntPtr A_0, Byte[] A_1, Int32 A_2, Int32 A_3, IntPtr A_4, f A_5, f A_6, a8 A_7)
at Devart.Data.SQLite.a7.a(String A_0, Int32 A_1, f A_2, f A_3, a8 A_4)
at Devart.Data.SQLite.SQLiteConnection.a(SQLiteFunction A_0, Boolean A_1)
at Devart.Data.SQLite.SQLiteConnection.a()
at Devart.Data.SQLite.SQLiteConnection.Open()
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation)
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
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.Infrastructure.DefaultExecutionStrategy.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.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2[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.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
at System.Data.Entity.Internal.Linq.InternalSet`1.FindInStore(WrappedEntityKey key, String keyValuesParamName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues)
at System.Data.Entity.DbSet`1.Find(Object[] keyValues)
stephen.black
 
Posts: 2
Joined: Fri 06 Jan 2017 10:50

Re: System.OutOfMemoryException thrown on Open()

Postby Shalex » Fri 06 Jan 2017 19:09

Please make sure that your application loads sqlite3.dll supplied with the dotConnect for SQLite installation. Take into account:
  • another sqlite3.dll may reside in a system folder (C:\Windows\System32\)
  • depending on the mode of your application (x86 or x64), the corresponding version (x86 or x64) of sqlite3.dll is loaded in the process of your application
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Re: System.OutOfMemoryException thrown on Open()

Postby stephen.black » Thu 12 Jan 2017 11:01

Hello,

There isn't a copy of the sqlite3.dll in system32, although we do use SqlCipher so the copy of the sqlite3 binary is not the one suplied with dotConnect. Would this cause any problems? I believe you do support it.

Thanks

Sj
stephen.black
 
Posts: 2
Joined: Fri 06 Jan 2017 10:50

Re: System.OutOfMemoryException thrown on Open()

Postby Shalex » Thu 12 Jan 2017 14:43

The stack trace says that the problem occurs on opening connection (not EF specific). Looks like your sqlite3.dll takes much memory when descrypting database. Could you reproduce the error with your encrypted database using the following simple test cases (case 1 and case 2)?
Code: Select all
    // https://www.devart.com/dotconnect/sqlite/docs/?SQLCipher.html

    string connString = "Data Source=YourEncryptedDatabase.db;Encryption=SQLCipher;Password=YourPassword; Pooling=false;"; // case 1
    // string connString = "Data Source=YourEncryptedDatabase.db;Encryption=SQLCipher;Password=YourPassword; Pooling=true;"; // case 2

    for (int i = 0; i < 1000; i++) {
        using (var conn = new SQLiteConnection(connString)) {
            conn.Open();
            var cmd = conn.CreateCommand();
            cmd.CommandText = "select " + i;
            Console.WriteLine(cmd.ExecuteScalar());
            conn.Close();
        }
    }
    Console.ReadKey();
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for SQLite