I'm trying to update a record in a database through C# code. I found a solution that I think should work using SaveChanges. However, I'm getting an error from my catch statement that says: "An error occurred while starting a transaction on the provider connection. See the inner exception for details." I'm either looking for an answer on how to fix it and/or how to make my catch statement give better details on what the problem actually is.
This is my code.
using var orderContext =
new OrderContext(Resources.SqlAuthenticationConnectionString);
foreach(OrderRecord order in orders)
{
var query =
from o in orderContext.OrderRecords
where o.ID == order.ID
select o;
foreach(OrderRecord record in query)
{
record.HeatLotNumber = order.HeatLotNumber;
record.OrderNumber = order.OrderNumber;
record.ShimCenterMaterial = order.ShimCenterMaterial;
try
{
orderContext.SaveChanges();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}