提交数据库事务时报告了错误 [英] An error was reported while committing a database transaction
问题描述
Hello Guys
我使用实体框架将10000条记录导入数据库(MS-SQL)。但是有一段时间我随机给出了一个错误: -
提交数据库事务时报告了错误,但无法确定数据库服务器上的事务是成功还是失败。有关详细信息,请参阅内部异常和http://go.microsoft.com/fwlink/?LinkId=313468。
我尝试过:
public int saveCarrierTransaction(CarrierTransactionModel模型)
{
尝试
{
var entity = Mapper.Map< CarrierTransactionModel,CarrierTransaction>(型号);
if(entity == null)
throw new ArgumentNullException(nameof(CarrierTransactionModel),CarrierTransactionModel不是实体地图);
var isExist = _carrierTransactionRepository.Any(x => x.AccountNumber == entity.AccountNumber&& x.Balance == entity.Balance&& x.CubicValue == entity.CubicValue&& x.DateTime == entity.DateTime&&
x.DeclaredValue == entity.DeclaredValue&& x.DeliveryDate == entity.DeliveryDate&am磷;&安培; x.Destination == entity.Destination&& x.DestinationAddress == x.DestinationAddress&& x.DestinationCity == entity.DestinationCity&&
x.DestinationCompanyName == entity.DestinationCompanyName& ;& x.DestinationCountry == entity.DestinationCountry&& x.DestinationName == entity.DestinationName&& x.DestinationState == entity.DestinationState&&
x.DestinationZip == entity .DestinationZip&安培;&安培; x.DimensionalWeight == entity.DimensionalWeight&安培;&安培; x.Email == entity.Email&安培;&安培; x.GroupCode == entity.GroupCode&安培;&安培; x.Height == entity.Height&安培;&安培; X .IsCubic == entity.IsCubic&&
x.Length == entity.Length&& x.MailClass == entity.MailClass&& x.OptionalServices == entity.OptionalServices&& ; x.Origin == entity.Origin&安培;&安培; x.PackageDescription == entity.PackageDescription&& x.Phone == entity.Phone&&
x.PostageAmt == entity.PostageAmt&& x.Postmark == entity.Postmark& & x.Reference2 == entity.Reference2&& x.Reference3 == entity.Reference3&& x.Reference4 == entity.Reference4&& x.ReferenceID == entity .ReferenceID&& x.RefundStatus = = entity.RefundStatus&&
x.StatusCode == entity.StatusCode&& x.StatusDescription == entity.StatusDescription&& x.Total == entity.Total&& x。 TrackingNumber == entity.TrackingNumber&& x.TransactionId == entity.TransactionId&& x.Type == entity.Type&&
x.Weight == entity.Weight&& x.Width == entity.Width&& x.Zone == entity.Zone);
if(isExist)
return 0;
_carrierTransactionRepository.Insert(entity);
Syst em.Console.Error.WriteLine(Insert CarrierTransaction:+ entity.AccountNumber);
// Log.WriteToFile(Insert CarrierTransaction:+ entity.AccountNumber);
return _carrierTransactionRepository.Save();
}
catch(例外情况)
{
日志。 WriteToFile(Error:+ ex.Message);
System.Console.Error.WriteLine(Error:+ ex.Message);
throw ex; < br $>
}
}
Hello Guys
I am importing 10000 records into the database(MS-SQL) using entity framework.But some time gives me an error randomly:-
An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server. See the inner exception and http://go.microsoft.com/fwlink/?LinkId=313468 for more information.
What I have tried:
public int saveCarrierTransaction(CarrierTransactionModel model)
{
try
{
var entity = Mapper.Map<CarrierTransactionModel, CarrierTransaction>(model);
if (entity==null)
throw new ArgumentNullException(nameof(CarrierTransactionModel), "CarrierTransactionModel is not map with entity ");
var isExist = _carrierTransactionRepository.Any(x => x.AccountNumber == entity.AccountNumber && x.Balance == entity.Balance && x.CubicValue == entity.CubicValue && x.DateTime == entity.DateTime &&
x.DeclaredValue == entity.DeclaredValue && x.DeliveryDate == entity.DeliveryDate && x.Destination==entity.Destination &&x.DestinationAddress==x.DestinationAddress&&x.DestinationCity==entity.DestinationCity&&
x.DestinationCompanyName==entity.DestinationCompanyName&&x.DestinationCountry==entity.DestinationCountry&&x.DestinationName==entity.DestinationName&&x.DestinationState==entity.DestinationState&&
x.DestinationZip==entity.DestinationZip&&x.DimensionalWeight==entity.DimensionalWeight&&x.Email==entity.Email&&x.GroupCode==entity.GroupCode&&x.Height==entity.Height&&x.IsCubic==entity.IsCubic&&
x.Length==entity.Length&&x.MailClass==entity.MailClass&&x.OptionalServices==entity.OptionalServices&&x.Origin==entity.Origin&& x.PackageDescription==entity.PackageDescription&&x.Phone==entity.Phone&&
x.PostageAmt==entity.PostageAmt&&x.Postmark==entity.Postmark&&x.Reference2==entity.Reference2&&x.Reference3==entity.Reference3&&x.Reference4==entity.Reference4&&x.ReferenceID==entity .ReferenceID&&x.RefundStatus==entity.RefundStatus&&
x.StatusCode==entity.StatusCode&&x.StatusDescription==entity.StatusDescription&&x.Total==entity.Total&&x.TrackingNumber==entity.TrackingNumber&&x.TransactionId==entity.TransactionId&&x.Type==entity.Type&&
x.Weight==entity.Weight&&x.Width==entity.Width&&x.Zone==entity.Zone);
if (isExist)
return 0;
_carrierTransactionRepository.Insert(entity);
System.Console.Error.WriteLine("Insert CarrierTransaction: " + entity.AccountNumber);
// Log.WriteToFile("Insert CarrierTransaction: " + entity.AccountNumber);
return _carrierTransactionRepository.Save();
}
catch (Exception ex)
{
Log.WriteToFile("Error: " + ex.Message);
System.Console.Error.WriteLine("Error: " +ex.Message);
throw ex;
}
}
推荐答案
如果你真的去了给出的页面他们在例外报告中为您提供了三种可能的解决方案
Microsoft建议 [ ^ ]
我不是nk你会在这里得到更好的建议
If you actually go to the page given to you in the exception report they give you three possible solutions
Microsoft suggesstions[^]
I don't think you'll get any better advice here
这篇关于提交数据库事务时报告了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!