I have an issue when I call db.SaveChanges()
method. Even if in the connectionString, I have MultipleActiveResultSets=True
and I'm using ToList()
method when I'm reading from database, when I call db.SaveChanges()
, I'm getting the error from the title of the question.
Here is my connection string:
<connectionStrings><add name="DBEntities" connectionString="metadata=res://*/DBEntities.csdl|res://*/DBEntities.ssdl|res://*/DBEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=.\ServerName;initial catalog=DatabaseName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
Here is my c# code:
db.SaveChanges();
int errorTrans = (from el in this.curentHandbackFile.Root.Element("data").Elements("Transaction") where el.Attribute("rrc").Value.Contains("_NOK_") select el).Count();
IEnumerable<XAttribute> integratedTrans = from el in this.curentHandbackFile.Root.Element("data").Elements("Transaction").Attributes("rrc") where el.Value.Contains("_OK_") select el;
int warningTransactionsCount = integratedTrans.Where(trans => trans.Value != ReturnCodes.RecordCodes.TransactionImported.Key).ToList().Count;
int successTransactionsCount = integratedTrans.Where(trans => trans.Value == ReturnCodes.RecordCodes.TransactionImported.Key).ToList().Count;
_import.Successes = successTransactionsCount;
_import.Errors = errorTrans;
_import.Warnings = warningTransactionsCount;
db.SaveChanges();
when I call the second time db.SaveChanges()
, I'm getting the error. Any idea why?
PS: I'm using .NET 3.5