SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

Out Of Memory Exception

Open jamessdixon opened this issue 6 years ago • 3 comments

Description

I have a table with 743537 records Select count(*) from [dbo].[ADDRESS] Running the TP against it causes an OOM exception

Repro steps

When I run this code: let [<Literal>] connectionString = "Data Source=XXX;Initial Catalog=XXX;User ID=XXX;password=XXX" type Provider = SqlDataProvider<ConnectionString = connectionString> let context = Provider.GetDataContext() let address = context.Dbo.Address |> Seq.head

I get this: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Expected behavior

A row of data returned

Actual behavior

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding) at System.Text.EncodingNLS.GetString(Byte[] bytes, Int32 index, Int32 count) at System.Data.SqlClient.TdsParserStateObject.TryReadStringWithEncoding(Int32 length, Encoding encoding, Boolean isPlp, String& value) at System.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj, SqlCommandColumnEncryptionSetting columnEncryptionOverride, String columnName) at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly) at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at <StartupCode$FSharp-Data-SqlProvider>.$SqlRuntime.DataContext.FSharp-Data-Sql-Common-ISqlDataContext-ReadEntities@210.GenerateNext(IEnumerable1& next) at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1.MoveNextImpl() at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1.System-Collections-IEnumerator-MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable1 source) at FSharp.Data.Sql.Runtime.QueryImplementation.executeQuery(ISqlDataContext dc, ISqlProvider provider, SqlExp sqlExp, List1 ti) at FSharp.Data.Sql.Runtime.QueryImplementation.SqlQueryable1.System-Collections-Generic-IEnumerable1-GetEnumerator() at Microsoft.FSharp.Collections.SeqModule.Head[T](IEnumerable1 source)

Known workarounds

None

Related information

  • Used database - Microsoft SQL Server Enterprise Edition (64-bit) - 10.50.6220.0
  • Operating system - Win 7 Enterprise 64 bit, 16 GB RAM
  • Branch
  • .NET Framework 4.6.1, F# 4.3.1
  • IDE VS2017 Enterprise
  • Performance information, links to performance testing scripts

jamessdixon avatar May 19 '18 23:05 jamessdixon

if you do: query {...} it's translated to sql query rather than fetching all.

Thorium avatar May 20 '18 09:05 Thorium

But it still shouldn't throw an OOM.

jamessdixon avatar May 20 '18 11:05 jamessdixon

But it still shouldn't throw an OOM.

It's what happened, so it's the right exception to throw. If you had (a lot) more RAM, it could have successfully loaded the whole table in memory, then taken the first row.

piaste avatar May 20 '18 11:05 piaste