Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TdsParserStateObject - disposing ? Entity Framework

I'm using EF and have problem with TdsParserStateObject.

I'm calling this method many times :

 public void SaveDataFromERP(string synchronizationType, string xml,int errorsHandlingPercentagePartition)
    {
        var param1 = new SqlParameter("XML", SqlDbType.Xml);
        param1.Value = xml;
        var param2 = new SqlParameter("PartitionedPackagePercentage", SqlDbType.Int);
        param2.Value = errorsHandlingPercentagePartition;
        ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<dynamic>(
            $"exec [Synchronization].[Import{synchronizationType}] @XML,  @PartitionedPackagePercentage", param1 , param2 );
}

My repository consists of

SynchronizationRepository : ISynchronizationRepository
{
  private readonly POSDBContext _context = new POSDBContext();
  public void SaveData(string typeName, string xmlFile, int errorsHandlingPartitionPercentage)
    {
        _context.SaveData(typeName, xmlFile,errorsHandlingPartitionPercentage);
    }
 }

When I call ExecuteStoreQuery I can see new object in memory TdsParserStateObject.

Unfortunately I must call this method in sequence many times(a lot of data). The result is about 60 TdsParserStateObject and it take a lot of memory.

Moreover these objects do not disappear after some time.

Is it possible to dispose them ?

enter image description here

like image 717
adamo94 Avatar asked Mar 31 '16 10:03

adamo94


1 Answers

Resolved my own issue to some degree by removing:

"MultipleActiveResultSets=True"

From my connection string. My connections were being made on background threads so this goes someway to explaining why I was seeing the increase:

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets

like image 127
Shovers_ Avatar answered Oct 01 '22 06:10

Shovers_