|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TableAdapters and transactionsHow to work with tableAdapters and transactions?
I see no Connection or Transaction property in TableAdapters. This guy is doing something with reflection: http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx Isn't there a better way, something like best practise? I wouldn't recommend reflection because you'll need full privileges to do
that. Instead you have at least two options: 1. avoid table adapters and do coding by yourself 2. expose connection by creating a partial class -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "TheMaxx" <themaxxREM***@net.hr> wrote in message news:erbqic$mn2$1@magcargo.vodatel.hr... > How to work with tableAdapters and transactions? > I see no Connection or Transaction property in TableAdapters. > This guy is doing something with reflection: > http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx > > Isn't there a better way, something like best practise? > 1. TableAdapters save A LOT of work (creating Inser/Update/delete commnds
for each table in my DB), please tell me : Do you create those methods manually? 2. and do this for each TableAdapter that needs to be updated with transaction) souds too much additional work to add on generated code. This all sound like walkarounds, what did Microsoft have in mind for this kind of situatisons? Show quote "Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:euTybbCVHHA.3996@TK2MSFTNGP04.phx.gbl... >I wouldn't recommend reflection because you'll need full privileges to do >that. Instead you have at least two options: > 1. avoid table adapters and do coding by yourself > 2. expose connection by creating a partial class > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > "TheMaxx" <themaxxREM***@net.hr> wrote in message > news:erbqic$mn2$1@magcargo.vodatel.hr... >> How to work with tableAdapters and transactions? >> I see no Connection or Transaction property in TableAdapters. >> This guy is doing something with reflection: >> http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx >> >> Isn't there a better way, something like best practise? >> > I can't speak for others, but I create those methods manually. I am
actually working on a routine that creates strongly typed datasets from my stored procedures, and doesn't create the table adapters. I'll use stored procedures for the updates, and write my own code to call them. You only have to write it once (unless something changes), and you have more control over it. A lot of people use the TableAdapters, though. Robin S. ----------------------------- Show quote "TheMaxx" <themaxxREM***@net.hr> wrote in message news:erm8ab$ss8$1@magcargo.vodatel.hr... > 1. TableAdapters save A LOT of work (creating Inser/Update/delete commnds > for each table in my DB), please tell me : Do you create those methods > manually? > 2. and do this for each TableAdapter that needs to be updated with > transaction) souds too much additional work to add on generated code. > This all sound like walkarounds, what did Microsoft have in mind for this > kind of situatisons? > > > > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message > news:euTybbCVHHA.3996@TK2MSFTNGP04.phx.gbl... >>I wouldn't recommend reflection because you'll need full privileges to do >>that. Instead you have at least two options: >> 1. avoid table adapters and do coding by yourself >> 2. expose connection by creating a partial class >> >> -- >> Miha Markic [MVP C#, INETA Country Leader for Slovenia] >> RightHand .NET consulting & development www.rthand.com >> Blog: http://cs.rthand.com/blogs/blog_with_righthand/ >> >> "TheMaxx" <themaxxREM***@net.hr> wrote in message >> news:erbqic$mn2$1@magcargo.vodatel.hr... >>> How to work with tableAdapters and transactions? >>> I see no Connection or Transaction property in TableAdapters. >>> This guy is doing something with reflection: >>> http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx >>> >>> Isn't there a better way, something like best practise? >>> >> > > To use transactions with table adapters you can use TransactionScope:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { using (SqlConnection connection = new SqlConnection(ConnectionString)) { try { // Put code here scope.Complete(); // Call this to notify that a transaction is finished } catch (Exception ex) { // Exception code here } } } If scope.Complete() is not called the transaction will back out. Note how the TransactionScope is called prior to the "new SqlConnection". Hope this he;ps. Show quote "TheMaxx" wrote: > How to work with tableAdapters and transactions? > I see no Connection or Transaction property in TableAdapters. > This guy is doing something with reflection: > http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx > > Isn't there a better way, something like best practise? > > > Scott, i think you are missing a point.
I need code where you put: "// Put code here" Show quote :) "Scott" <Sc***@discussions.microsoft.com> wrote in message news:924835D0-2367-4F09-937C-17EAABE1705C@microsoft.com... > To use transactions with table adapters you can use TransactionScope: > > using (TransactionScope scope = new > TransactionScope(TransactionScopeOption.RequiresNew)) > { > using (SqlConnection connection = new SqlConnection(ConnectionString)) > { > try > { > // Put code here > scope.Complete(); // Call this to notify that a transaction is > finished > } > catch (Exception ex) > { > // Exception code here > } > } > } > > If scope.Complete() is not called the transaction will back out. > Note how the TransactionScope is called prior to the "new SqlConnection". > Hope this he;ps. > > "TheMaxx" wrote: > >> How to work with tableAdapters and transactions? >> I see no Connection or Transaction property in TableAdapters. >> This guy is doing something with reflection: >> http://mybug.bloger.hr/post/tableadapters-and-transactions/179426.aspx >> >> Isn't there a better way, something like best practise? >> >> >> |
|||||||||||||||||||||||