473,748 Members | 5,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transaction issue

I'm inserting info in database when clicking a button. Some procedure are
called. I want to do that with a transaction (when clicking on the button
and within its procedure) so that everything will be
inserted or nothing. How to do that? Thanks

Private Sub btnRegister_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s)
addExtPartyList ToDB()

AddReminderDB()

addCostSplitDB( )

AddMoneyDB()

AddinfoDB()

AddmemberDB()
end sub
Nov 19 '05 #1
2 1062
There's several ways to approach this. You could use COM+ (Enterprise
Services) and require transactions, but the simplest is to use the
SqlTransaction object:

Here's a brief excerpt. It assumes you are using SQL Server and
SqlDataAdapters .

// Create a SqlTranaction
SqlTransaction trans;
trans = myConnection.Be ginTransaction( );
try
{
// Assign the correct adapters and Commands to the transaction;
// These can be Update, Insert, or Delete Commands;
dataAdapter1.Up dateCommand.Tra nsaction = trans;
dataAdapter2.In sertCommand.Tra nsaction = trans;
dataAdapter3.De leteCommand.Tra nsaction = trans;

// Call the update methods for each adapter involved in the transaction;
dataAdapter1.Up date(dataset);
dataAdapter2.Up date(dataset);
dataAdapter3.Up date(dataset);

// Commit the transaction;
trans.Commit();
}
catch(Exception e)
{
//If an exception occurs, then we need to rollback the transaction;
trans.Rollback( );
}
Hope this helps.
Dave
"viktor9990 " <vi********@dis cussions.micros oft.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
I'm inserting info in database when clicking a button. Some procedure are
called. I want to do that with a transaction (when clicking on the button
and within its procedure) so that everything will be
inserted or nothing. How to do that? Thanks

Private Sub btnRegister_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s)
addExtPartyList ToDB()

AddReminderDB()

addCostSplitDB( )

AddMoneyDB()

AddinfoDB()

AddmemberDB()
end sub

Nov 19 '05 #2
You have some options:

1) Use ADO.NET to create a transaction and then pass it to each method so
that the method can use it to join the transaction

2) Create a "Transactio n" class that inherits from the ServicedCompone nt
class in the Enterprise Services namespace and then use the "Transactio n"
attribute to declare that you want the DTC (Distributed Transaction
Coordinator) to create a transaction for you. This "Transactio n" class would
have a method that would in turn call the other methods and also act as the
root of the transaction.

3) This option uses enterprise services in a different way that you might
want to check out:
http://blogs.msdn.com/florinlazar/ar...24/194199.aspx
"viktor9990 " wrote:
I'm inserting info in database when clicking a button. Some procedure are
called. I want to do that with a transaction (when clicking on the button
and within its procedure) so that everything will be
inserted or nothing. How to do that? Thanks

Private Sub btnRegister_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s)
addExtPartyList ToDB()

AddReminderDB()

addCostSplitDB( )

AddMoneyDB()

AddinfoDB()

AddmemberDB()
end sub

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7515
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I have an series of interactive HTML forms. The user begins a Cookie session. A database connection is opened and a transaction is begun. After the user goes through any number of pages where they update the database they finish on a page where...
1
439
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? I have read the doc regarding this: http://www.developer.com/net/asp/article.php/3385631 but it will not work when methods are in different services on
0
1838
by: Manoj Sharma | last post by:
I am performance testing some batch processing engines. These are written in ..NET and SQL Server and are typically concerned with generating XML files out of data retrieved from the database. I have two machines one running IIS Server and the other SQL Server. Problem Description: One of the engines is failing with the following exception:
4
6719
by: Leaf | last post by:
Greetings, I've been reading with interest the threads here on deadlocking, as I'm finding my formerly happy app in a production environment suddenly deadlocking left and right. It started around the time I decided to wrap a series of UPDATE commands with BEGIN/END. The gist of it is I have a .NET app that can do some heavy reading (no writing) from tblWOS. It can take a minute or so to read all the data into the app, along with data...
8
2599
by: Alex | last post by:
Hi, I have a test system that is setup the same as a production system and would like to frequently copy the database over. pg_dump takes a few hours and even sometimes hangs. Are there any reasons not to simply just copy the entire data directory over to the test system? I could not find any postings on the net suggesting otherwise. Is there anything to pay attention too ?
12
2222
by: John Sidney-Woollett | last post by:
I have to convert an java web application currently using an Oracle DB back end to one using a Postgres backend. In Oracle much of the application logic is abstracted away from the java middleware layer using stored procedures within the Oracle database. There are certain features in Oracle that appear to be missing from Postgres which are causing us some concern, and we wondered how much we're going to have to butcher the backend and db...
15
10000
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried) 3-4 times and give up if after that it's still in deadlock. I'm very sure that many experienced people out there already deal with this issue somehow. Is there an alternative to it? Thanks for your comments and suggestions.
9
7616
by: John Sidney-Woollett | last post by:
Is it possible to use the dblink and dblink_exec features from inside pl/pgsql functions to mimic the behaviour of nested transactions by calling another function or executing some SQL via the dblink (into the same database)? Does the SQL statement executed within the dblink sit in its own isolated transaction/session? And would an error thrown in the dblink statement abort the enclosing session that initiated the call? What is the...
1
8335
by: Matik | last post by:
Hi to all, Probably I'm just doing something stupid, but I would like you to tell me that (if it is so), and point the solution. There ist the thing: I' having a sp, where I call other sp inside. The only problem is, the name of this inside sp is builded variously, and executed over sp_executesql:
3
2700
by: sifrah | last post by:
Hi All, My SQL server transaction log is getting bigger every day and my HDD if running out of space. So i follow the MS KB about how to Shrinking the Transaction Log. After doing so the log is much much smaller as i can see the size of it under enterprise manager. The problem is that the HDD still shows the same size. If i shrink the DB why the and reduce its size why the HDD does not
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.