I'm trying to copy data row by row from ProductStatisticsTemp
table to ProductStatistics
table.
[HttpGet]
public ActionResult Copy_DatatoProductStatistics()
{
string errormsg = "";
//var incomplete_product_result = db.Database.SqlQuery<ProductStatistics>("Copy_ProductStatistics");
var str = from a in db.ProductStatisticsTemp select a;
ProductStatistics ls = new ProductStatistics();
try
{
foreach (var val in str) // iterator the data from the list and insert them into the listSecond
{
var product = db.Product.Find(val.Product_ID);
try
{
if (product.ProductID == val.Product_ID & product.ProductTitleEn == val.ProductNameEn & product.ProductTitleAr == val.ProductNameAr)
{
try
{
if (!String.IsNullOrEmpty(val.SalesVolumes) | !String.IsNullOrEmpty(val.Target) | !String.IsNullOrEmpty(val.Profitability) | !String.IsNullOrEmpty(val.AnnualGrowthRate))
{
ls.Product_ID = val.Product_ID;
ls.ProductNameEn = val.ProductNameEn;
ls.ProductNameAr = val.ProductNameAr;
ls.Profitability = val.Profitability;
ls.Target = val.Target;
ls.SalesVolumes = val.SalesVolumes;
ls.Subsidary_ID = val.Subsidary_ID;
ls.AnnualGrowthRate = val.AnnualGrowthRate;
db.ProductStatistics.Add(ls);
}
db.SaveChanges();
}
catch (Exception ex)
{
errormsg = ex.Message;
}
}
}
catch (Exception ex)
{
errormsg = "Product ID or Product Name Doesnt match with existing details";
}
}
}
catch (Exception ex)
{
errormsg = ex.Message;
}
return RedirectToAction("FileUpload", "FileUpload", new { error = errormsg });
}
but after db.SaveChanges();
above line its directing to catch (Exception ex)
. once I debug I can see following inner exception message
Message = "New transaction is not allowed because there are other threads running in the session."