开发者

C# TransactionManager

开发者 https://www.devze.com 2023-02-28 01:47 出处:网络
Hi I have a generator which made some automated code (creating all the get, set, etc) for me structured by a Database, in this code there is a piece of code that is as follows:

Hi I have a generator which made some automated code (creating all the get, set, etc) for me structured by a Database, in this code there is a piece of code that is as follows:

SqlTransaction transaction = TransactionManager.GetTransaction();

I have added the r开发者_运维知识库eference and imported using System.Transactions; at the beginning of the file manually because the code generator never did this. Once imported, this removed the TransactionManager error I was getting but now I am receiving an error on .GetTransaction(); from what I have researched there is no such method in the TransactionManager.

Does anyone have any clue as to what should be in place of this code (the generator has some code which has to be replaced due to errors, my guess is this is one of those cases...). Any suggestions would be appreciated! Thanks in advance!


This answer presumes that the generator you are using was built in house and you are modifying it now - if it was an external code generator then you should check the manual for it around what references you need.

The TransactionManager class in System.Transactions does't actually create or enlist in transactions for you. It simply provides information about the current transactions. From MSDN:

This class contains static properties and methods used to obtain information about the default transaction options.

Instead I think you want either:

  • an explicit transaction from the sql connection object http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.aspx
  • or a transaction scope http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx

Googling TransactionManager it appears that people commonly write their own classes with this name which do things like offer a GetTransaction() method - possible this is why the generator has this name?


Adding just some Transaction namespaces should not help. You'll probably need some base DLL's or code files that come with the generator. Read the manual.


You typically start a SqlTransaction by calling BeginTransaction() on your current connection. Looks like your "Generator" uses some TransactionManager class which it generates or which is delivered with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消