Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SharePoint-检查项目是否由其他用户编辑_C#_Sharepoint_Sharepoint 2007_Deadlock - Fatal编程技术网

C# SharePoint-检查项目是否由其他用户编辑

C# SharePoint-检查项目是否由其他用户编辑,c#,sharepoint,sharepoint-2007,deadlock,C#,Sharepoint,Sharepoint 2007,Deadlock,希望有人能帮助我 使用SharePoint 2007基金会,我在C中设计了一个应用程序,部分是CAML查询,它返回订单传输的项目,基于输出,创建一个电子邮件附件并发送它。然后为每个项目设置新的状态,如“运输订单” 问题是: 若有人正在编辑应用程序设置新状态时抛出以下错误的同一项,则会发送带有附件的电子邮件,但状态保持不变,并且在下一次运行中为重复项 > System.Data.SqlClient.SqlException: Transaction (Process ID 89) was d

希望有人能帮助我

使用SharePoint 2007基金会,我在C中设计了一个应用程序,部分是CAML查询,它返回订单传输的项目,基于输出,创建一个电子邮件附件并发送它。然后为每个项目设置新的状态,如“运输订单”

问题是:

若有人正在编辑应用程序设置新状态时抛出以下错误的同一项,则会发送带有附件的电子邮件,但状态保持不变,并且在下一次运行中为重复项

> System.Data.SqlClient.SqlException: Transaction (Process ID 89) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.HasMoreRows()
   at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
   at System.Data.SqlClient.SqlDataReader.Read()
   at Microsoft.SharePoint.SPSqlClient.ExecuteQuery(Boolean& bSucceed)
   at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
   at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
   at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
   at Microsoft.SharePoint.SPListItemCollection.GetItemIndexById(Int32 id)
   at Microsoft.SharePoint.SPListItemCollection.GetItemById(Int32 id)
   at ImportExportTool.Program.OrderTransportation(SPList planningList, SPField statusField) in c:\Users\MacProWin\OneDrive\Work\ImportExportTool v30 - source code\Program.cs:line 368
有谁能告诉我如何检查项目是否由其他用户编辑,然后强制关闭它,或者建议更好的解决方案

以下是设置新状态的代码部分:

foreach (int orderItemId in orderedItemsIds)
                {

                    SPListItem orderedItem = planningList.Items.GetItemById(orderItemId);
                    Common.Log(String.Format("Status Doprava Objednana is now set to Item: '{0}'", orderItemId));
                    SPFieldMultiChoiceValue statuses = new SPFieldMultiChoiceValue(orderedItem[Properties.Settings.Default.StatusFieldName].ToString());

                    statuses.Add("Doprava objednána");
                    orderedItem[Properties.Settings.Default.StatusFieldName] = statuses;

                    orderedItem.Update();
                }
多谢各位


马雷克

据我所知,没有办法检测“未结”物品。您可以检查“修改”字段,但它仅显示上次更新的时间

从架构师的角度来看,最好将4-5次更新组合到单个更新操作中,以最小化死锁问题。您还应该检查字段中的当前值(比较实际值和要写入的值),以防止进行不必要的更新


从技术角度(解决出现的问题)来看,您应该首先执行操作,然后处理潜在的事务异常,重复您的操作(异常消息中建议的操作)。在成功的情况下,发送通知。

您是否已经在项目中启用了签入和签出。我不这样做,因为我们处理了大量的项目,每个项目都被编辑了4-5次,因为我们认为它是关闭的,所以我不能要求用户批准每个更改。基本上这太费时了。最好的解决方案是,如果我能识别打开的项目并将其跳到下一次运行。我不确定这是否可行,签入和签出将同时阻止其他人编辑文档。我知道这会增加用户编辑的时间,但对我来说,口是心非似乎是一个更大的问题。你是对的。只是稍微修改了代码,以便首先处理事务,如果成功,它将发送一封电子邮件。