Transaction and TypedDataSEt

L

liming

Hi,

I know it's possible to have transactions with Typed DataSet, but I have yet
to find an example of it.

For example, I have two typed TableAdapter

CommerceDataSet.xsd

CustomerTableAdapater

Insert(@CustomerName)

OrdersTableAdapater

Insert(@CustomerID, @ProductID)

My sample code

CustomerTableAdapater customer = new CustomerTableAdapater();
OrdersTableAdapater orders = new OrdersTableAdapater();
String customername = blah;
int customerid = 0, productid=0;
.....
......
customer.insert(customername);
.....
orders.insert(customerid,productid);

....



How do I hook up transaction to both "Insert" method, if one fails, roll
back? I have projects to finish up quickly in a month, and I prefer to use
these typed datatable as my datalayer for now as it does mostly what I
needed instead of implementing a whole layer myself manually using
EnterpriseLibrary which really gets me the same result against sql server
2000. Once I have this transaction issue resolved, I'm good to go.

Another question, what's your opinion in terms of implement my data layer
using Typed DataSet instead of my own classes? I do it right now beause it's
quicker, mainly saves me a lot keystrokes considerably. What other benefit
do you see? Just curious.

Thanks
 
S

Steven Cheng[MSFT]

Hello liming,

Welcome to the MSDN newsgroup.

From your description, I understand you're wondering the proper means to
perform transaction control when using multiple ADO.NET
tableadapter/typeddataset components in .NET application, correct?

As for ADO.NET, it used to provide connection specific transaction support,
that means the transaction's scope is limited to a single connection. Such
single connection specific transaction is started by calling the
"Connection.BeginTransaction" method and associating other command objects
with the returned transaction instance. According to your scenario, you
have multiple TableAdapters (each of them will have a connection object
associated with it), then I think you can consider use the new transaction
control feature provided in the .NET framework 2.0, it is under the
"System.Transaction" namespace.

You can just create a "TransactionScope" class instance and wrap other
connections/commands's creation code within this "TransactionScope"
instance's lifecycle, this will help implicitly establish a transaction
context. Here are some msdn articles mentioned this:

#Implementing an Implicit Transaction using Transaction Scope
http://msdn2.microsoft.com/en-us/ms172152.aspx

#System.Transactions Namespace
http://msdn2.microsoft.com/en-us/system.transactions.aspx

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Liming,

How are you doing on this issue? Does the information in my last reply
helps you a little? BTW, if you have any data access specific questions,
you can also post in the microsoft.public.dotnet.framework.adonet
newsgroup. There are also many ADO.NET experienced guys there who can help
you.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

PeterKellner

Hi Liming,

How are you doing on this issue? Does the information in my last reply
helps you a little? BTW, if you have any data access specific questions,
you can also post in the microsoft.public.dotnet.framework.adonet
newsgroup. There are also many ADO.NET experienced guys there who can help
you.

Regards,

Steven Cheng
Microsoft Online Community Support

Steven,

Not sure how Liming is doing, but you post helped me a lot. I had the
some wonder and before this didn't know about transaction scope.
Thanks.
Peter Kellner
http://peterkellner.net
 
S

Steven Cheng[MSFT]

Thanks for your input Peter,

Glad to be of assistance!

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top