我将按以下方式删除记录: -
string deleteWrongEntry = "DELETE FROM [" + schemaName + "].[Entry] WHERE CompanyId=" + companyId + " AND EmployeeId = " + StrECode + " AND Entry_Date = '" + StrInputDate.ToString("yyyy-MM-dd") + "'";
ctx.Database.ExecuteSqlCommand(deleteWrongEntry);
此代码位于foreach循环和&跑了2000多次。
我收到以下错误: -
事务(进程ID 59)在锁定时死锁通讯 用另一个进程缓冲资源并被选为 僵局受害者。重新运行该交易。
在堆栈跟踪中,我得到以下内容: -
- 在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action
1 wrapCloseInAction)
1 completion,String methodName,Boolean sendToPipe,Int32 timeout, Boolean asyncWrite) - at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() - at Glimpse.Ado.AlternateType.GlimpseDbCommand.ExecuteNonQuery() - at System.Data.Entity.Infrastructure.Interception.InternalDispatcher
--at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) --at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) --at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) --at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1.Dispatch[TInterceptionContext,TResult](Func
1 operation,TInterceptionContext interceptionContext,Action1 executing, Action
1执行)--at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(的DbCommand command,DbCommandInterceptionContext interceptionContext) - at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction [T](Func键1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) --at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass57.<ExecuteStoreCommand>b__55() --at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func
1 操作)--at Greytrix.Pocket.Data.TimeOffice.TimeOfficeInOutProcess.SaveTimeEntry(字符串 schemaName,Int32 companyId,DateTime fromDate,DateTime toDate)
--at Greytrix.Pocket.Data.TimeOffice.TimeOfficeInOutProcess.InOutImportProcess(String schemaName,Int32 companyId,DateTime fDate,DateTime tDate,Boolean flagAutoShift,布尔标志)--at TimeOffice.Controllers.UtilitiesController.InOutImport(的FormCollection form,String Command)
这是什么解决方案?
我可以为这2行添加一个try catch块,这样代码就可以进一步运行了。只会跳过受影响的记录吗?