Using ADO to run mulitple SQL statement in one transaction.

generic
Member Posts: 511
Hello.
I am doing an integration using ADO. My code looks something like below
I am executing two INSERT statement. which are separate transaction. So if second one fails the first one is COMMITED.
I wanted to know how I can run the two insert statements in same Transaction.
Thank you.
I am doing an integration using ADO. My code looks something like below
IF ISCLEAR(ADOCommand) THEN CREATE(ADOCommand); ActiveConnection := ADOConnection; ADOCommand.ActiveConnection := varActiveConnection; ADOCommand.CommandText := 'insert into Some table '; ADOCommand.CommandTimeout := 0; ADOCommand.Execute; ADOCommand.CommandText := 'insert into Some other table '; ADOCommand.CommandTimeout := 0; ADOCommand.Execute;
I am executing two INSERT statement. which are separate transaction. So if second one fails the first one is COMMITED.
I wanted to know how I can run the two insert statements in same Transaction.
Thank you.
0
Answers
-
do you have tested someting like this:
CommandText := TextConst1 + Command1 + Command2 + TextConst2;
TextConst1 is a TextConst with the value "beging trans"
TextConst1 is a TextConst with the value "commit trans" or "end trans"
Command1 is a TextConst with the value "insert into table XYZ values ABS"
Command2 is a TextConst with the value "go insert into table TZU values GHT"
?Do you make it right, it works too!0 -
Or you work with
AdoConn.BeginTrans
and
AdoConn.CommitTrans
The CommitTrans method saves all pending changes made since the last BeginTrans method call was used to initiate a transaction.
Also take a look here on the method RollbackTrans() if needed
RegardsDo you make it right, it works too!0 -
Thanks. That solved it. I'll update the heading.0
-
Please and welcomeDo you make it right, it works too!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions