System.OutOfMemoryException when adding a line with 1.300.000 char in azure sql server DB (work in local environment)

Renaud Roland 6 Reputation points
2022-02-09T07:04:25.97+00:00

Hello.

I get issue when i try to insert in Azure db a record with a nvarchar line that get 1.300.00 characters. The error log by app insight is :

An exception occurred while iterating over the results of a query for context type 'Library.EntityFramework.Context.GboContext'.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.String.Ctor(Char[] value, Int32 startIndex, Int32 length)
at Microsoft.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj, SqlCommandColumnEncryptionSetting columnEncryptionOverride, String columnName)
at Microsoft.Data.SqlClient.SqlDataReader.TryReadColumnData()
at Microsoft.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly)
at Microsoft.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()

The error occure when i try to insert the record on the database hosted in Azure, when i try to insert in locale database the record is added without problem.

Did someone had clue about the issue ?

Thx,

Renaud.

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Renaud Roland 6 Reputation points
    2022-02-17T08:24:59.02+00:00

    Hello,

    The problem was with a bad query that import for each record the line with 1.300.000 char ;)

    So we have solved the problem by refactoring the query.

    1 person found this answer helpful.
    0 comments No comments