SharePoint 2007: How can I perform a series of operations within a transaction?
Asked Answered
D

6

6

I would love to know how to perform a series of operations in a SharePoint context within a transaction. For example, I would like to be able to do something like the following:

context.BeginTransaction();
listItemA.Update();
listItemB.Update();
context.CommitTransaction();

I know this isn't possible with the OOTB APIs, but someone has got to have figured out how to accomplish this. Is it possible to get a reference to the database connection in order to handle the transaction? Or any other ideas?

Dody answered 19/2, 2009 at 0:18 Comment(0)
P
8

Although SharePoint technically uses SQL as a storage backing, we're not supposed to treat it like a database-based application. SP creates a faux-filesystem of sorts, which is what we interact with via the API. So from the developer perspective, Sharepoint is pretty much transaction-less.

Unfortunately that's pretty much all there is to it :) Even thinking about trying to get involved with the database directly will result in Old Testament pain. Rending of garments, wailing and gnashing of teeth ;)

Proponent answered 19/2, 2009 at 0:23 Comment(1)
Go SharePoint. Many years of relational theory and finely tuned implementations are trivialized.Goebel
T
6

Simply use Recycle(). Keep track of the GUID in a GUID[]. If one fails open de RecycleBin and restore/delete all by GUID

GUID[] guids = new GUID[];
SPWeb web;
SPListItem item;
SPList list;

try
{
    foreach item in list

    GUID current = item.Recycle()
    guids.add(current);

    item.Delete();
}
catch{
    if one fails : web.RecycleBin.Restore(guids);
}

if all succeed : web.RecycleBin.Delete(guids):
Thaumaturgy answered 10/2, 2010 at 14:36 Comment(0)
D
4

If you use versioning you could try a solution that checks out your item, performs updates and checks in. If rollback is needed, just undo the checkout.

Could work maybe??

Drouin answered 26/5, 2009 at 21:1 Comment(0)
B
1

Another option is to use workflow, mentioned here. As stated in How Windows SharePoint Services Processes Workflow Activities:

Windows SharePoint Services runs the workflow until it reaches a point where it cannot proceed because it is waiting for some event to occur: for example, a user must designate a task as completed. Only at this "commit point" does Windows SharePoint Services commit the changes made in the previous Windows SharePoint Services-specific workflow activities. Those changes are batched into a single SQL transaction.

Beaverette answered 29/7, 2009 at 9:7 Comment(1)
This is kind of misleading. It refers to the serialization (dehydration) aspects of a Workflows. The same can be said that invoking "Update" on an SPListItem is a "commit point". However, it is a singular operation that supports no transactions.Goebel
U
0

No Sharepoint does not provide SQL server like transaction capability.

As Rutger Hemrika posted, thats a far better way of doing it than anyhing else that I have seen until now.

Unbiased answered 20/11, 2012 at 10:47 Comment(0)
I
0

Sharepoint does not offer transaction support out of the box. Here is a good resource on Building a System.Transactions resource manager for SharePoint Though I would save the effort and store any critical data directly into a RDB.

Infusorian answered 5/1, 2015 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.