An error occurred while starting a transaction on the provider connection

时间:2021-06-07 18:26:26
An error occurred while starting a transaction on the provider connection. See the inner exception for details.

   at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.EntityClient.EntityConnection.BeginTransaction()     at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     at System.Data.Entity.Internal.InternalContext.SaveChanges()     at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()     at System.Data.Entity.DbContext.SaveChanges()     at OMIS.Data.EfRepository`1.Insert(T entity)     at OMIS.Services.TaskPlans.TaskPlanService.GenerationTaskImplementForDevice(TaskPlan taskPlan, TaskImplement taskImplement, IEnumerable`1 patrolStandardInfoList, IEnumerable`1 taskPlanDeviceMeasureParameters, TaskPlanDevice taskPlanDevice)


代码如下:
foreach (PatrolStandardInfo oldPatrolStandardInfo in oldPatrolStandardInfos)
                        {
                            if (!oldPatrolStandardInfo.IsDeleted)
                            {
                                int versionFlag = 0;
                                foreach (StandardInfoVersion oldVersion2 in oldPatrolStandardInfo.Versions)
                                {
                                    try
                                    {
                                        if (!oldVersion2.IsDeleted)
                                        {
                                            if (versionFlag == 0)
                                            {
                                                patrolStandardInfo = new PatrolStandardInfo();
                                                patrolStandardInfo.Type = (short)PatrolStandardType.TaskImplement.GetHashCode();
                                                patrolStandardInfo.TypeId = taskImplementDevice.Id;
                                                patrolStandardInfo.ParentId = oldPatrolStandardInfo.Id;
                                                patrolStandardInfo.StandardType = oldPatrolStandardInfo.StandardType;
                                                _patrolStandardInfoRepository.Insert(patrolStandardInfo);
                                            }
                                            standardInfoVersion = new StandardInfoVersion();
                                            standardInfoVersion.PatrolStandardInfoId = patrolStandardInfo.Id;
                                            standardInfoVersion.StandardInfoId = oldVersion2.StandardInfoId; 
                                            _standardInfoVersionRepository.Insert(standardInfoVersion);
                                            versionFlag++;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        string sql = string.Format("Insert into Trace(ExceptionMsg,TraceLog) values ('{0}','{1}')", "GenerationTaskImplementForDevice" + ex.Message.Replace("'", "''"), ex.StackTrace.Replace("'", "''"));
                                        DBHelper.Conn.ExecuteSql(sql);
                                        throw ex;
                                    }
                                }
                            }
                        }

这个是什么原因导致的呢?请教高手,谢谢。

4 个解决方案

#1


See the inner exception for details

#2


引用 1 楼 xdashewan 的回复:
See the inner exception for details


detail: 
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.EntityClient.EntityConnection.BeginTransaction()     at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     at System.Data.Entity.Internal.InternalContext.SaveChanges()     at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()     at System.Data.Entity.DbContext.SaveChanges()     at OMIS.Data.EfRepository`1.Insert(T entity)     at OMIS.Services.TaskPlans.TaskPlanService.GenerationTaskImplementForDevice(TaskPlan taskPlan, TaskImplement taskImplement, IEnumerable`1 patrolStandardInfoList, IEnumerable`1 taskPlanDeviceMeasureParameters, TaskPlanDevice taskPlanDevice)

#3


ex.Message:An error occurred while starting a transaction on the provider connection. See the inner exception for details.

#4


引用 2 楼 fisea 的回复:
detail: 
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.EntityClient.EntityConnection.BeginTransaction()     at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     at System.Data.Entity.Internal.InternalContext.SaveChanges()     at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()     at System.Data.Entity.DbContext.SaveChanges()     at OMIS.Data.EfRepository`1.Insert(T entity)     at OMIS.Services.TaskPlans.TaskPlanService.GenerationTaskImplementForDevice(TaskPlan taskPlan, TaskImplement taskImplement, IEnumerable`1 patrolStandardInfoList, IEnumerable`1 taskPlanDeviceMeasureParameters, TaskPlanDevice taskPlanDevice)

这是StackTrace堆栈信息,你要看的是 inner exception

#1


See the inner exception for details

#2


引用 1 楼 xdashewan 的回复:
See the inner exception for details


detail: 
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.EntityClient.EntityConnection.BeginTransaction()     at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     at System.Data.Entity.Internal.InternalContext.SaveChanges()     at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()     at System.Data.Entity.DbContext.SaveChanges()     at OMIS.Data.EfRepository`1.Insert(T entity)     at OMIS.Services.TaskPlans.TaskPlanService.GenerationTaskImplementForDevice(TaskPlan taskPlan, TaskImplement taskImplement, IEnumerable`1 patrolStandardInfoList, IEnumerable`1 taskPlanDeviceMeasureParameters, TaskPlanDevice taskPlanDevice)

#3


ex.Message:An error occurred while starting a transaction on the provider connection. See the inner exception for details.

#4


引用 2 楼 fisea 的回复:
detail: 
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.EntityClient.EntityConnection.BeginTransaction()     at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     at System.Data.Entity.Internal.InternalContext.SaveChanges()     at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()     at System.Data.Entity.DbContext.SaveChanges()     at OMIS.Data.EfRepository`1.Insert(T entity)     at OMIS.Services.TaskPlans.TaskPlanService.GenerationTaskImplementForDevice(TaskPlan taskPlan, TaskImplement taskImplement, IEnumerable`1 patrolStandardInfoList, IEnumerable`1 taskPlanDeviceMeasureParameters, TaskPlanDevice taskPlanDevice)

这是StackTrace堆栈信息,你要看的是 inner exception