Transaction deal

How does the transaction area work? How does he know when a different context is already in use and how can I implement a different kind of scope in my code.

I am primarily a vb.net developer, but I can read C # if you write in this.

In case the above was too vague:

I understand what system.transactions is and how to use it. I want to know how to create something similar, my own library that I can wrap around some code that can handle it the same way it does in the system.transactions scope. I am planning to use this with a caching model and it will improve it greatly. I'm looking for details on how the transaction scope knows, for example that the parent scope exists and so it can attach to it and the like, or that the commit should be done at a higher level or in a higher pin.

For example, if I have the following

using scope1 as new system.transactions.scope
    using scope2 as new system.transactions.scope
        using scope3 as new system.transactions.scope
             scope3.commit
        end using
        scope2.commit
    end using
end using

      

Scope1 will not capture, and therefore there will not be scope2 or scope3 since the parent of them is scope1. I would like to be able to customize this with my own libraries.

+1


source to share


5 answers


I suggest the article Introducing System.Transactions Juval Lowy



+7


source


I'll take a hit, but I'm not 100% sure of the question.

Deals in terms of databases tend to have areas. This indicates the coverage of the amount of data that changes in a transaction. They are implemented on the database server and cannot be changed "in code". Each database server will have its own implementation, and each server (oracle, MSSQL, MySQL) will have its own behavior.

Typically, a transaction will block any other connections from reading data that are in the middle of a change. The transaction volume will start as low as possible and then expand as the data volume increases. It is best to block as little data as possible in the database, and this does it:

  • Locking one column in one row of data
  • then locking one row of data
  • then lock the data page (8096 bytes perhaps?)
  • then locking the entire data table


If your update changes multiple rows of data, the transaction volume will expand to the page size (configurable per server) or to lock the entire table. Some database servers will allow other connections to read the table as they did before the update while the transaction is in progress, and other database servers will block any data fetches until the transaction is complete.

Basically, the point is that you cannot change the way the server is implemented, and the scope of transactions is not something that you should worry too much about. Just make sure that transactions are only used in compressed updates that depend on each other. I usually don't use transactions. But again, I don't work with bank accounts or any other critical systems.

Hope this helps!

0


source


Your question is rather ambiguous, so it's hard to know what you are really asking and looking for as an answer, but maybe this will help?

http://www.codeproject.com/KB/dotnet/TransactionScope20.aspx

0


source


I think I found a solution to reproduce the behavior of the scope. I'll post the info shortly, but it basically includes an idisposable implementation with a static value to keep track of nested object instances. To hook it up to a cache provider, I plan on using a list of arrays of the cached object and then triggering some cleanup when the object is deleted. I think I also know how to deal with flow problems, but I am still working through logistics. When I am done, I will release the code so that it can be deployed on top of speed to convey some of the current problems I am facing.

0


source


I don't know how System.Transactions works internally, but you can achieve this using thread-local memory. In .NET, the ThreadStatic attribute will give you this. Declare your context context something like this:

[ThreadStatic]
private static Context scopeContextThingy;

      

and there will be exactly one scopeContextThingy in the thread. Then, if scopeContextThingy == null

, you are a parent and must create a new context. Otherwise, you are a nested scope.

0


source







All Articles