Home All Groups Group Topic Archive Search About

TableAdapters and transactions

Author
19 Feb 2007 9:36 AM
TheMaxx
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?

Author
19 Feb 2007 1:06 PM
Miha Markic [MVP C#]
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/

Show quote
"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?
>
Author
23 Feb 2007 8:32 AM
TheMaxx
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?
>>
>
Author
23 Feb 2007 6:55 PM
RobinS
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?
>>>
>>
>
>
Author
20 Feb 2007 2:31 AM
Scott
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?
>
>
>
Author
23 Feb 2007 8:26 AM
TheMaxx
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?
>>
>>
>>

AddThis Social Bookmark Button