Update Multiple DataAdapters with one Sql Transaction

hello, am trying to implement a save routine , common scenario master detail data . However after the first save succeed the second time the save fails with the common message.
Concurrency Violation The Update affect....  
I have the following function Save
Private Function _Save() As Boolean
_Save = False
Dim con As New SqlClient.SqlConnection(connectionString)
con.Open()
Dim Tran As SqlClient.SqlTransaction = con.BeginTransaction
Try
MasterTA.InsertCommand = Masterbuilder.GetInsertCommand
MasterTA.UpdateCommand = Masterbuilder.GetUpdateCommand
MasterTA.DeleteCommand = Masterbuilder.GetDeleteCommand
MasterTA.InsertCommand.Transaction = Tran
MasterTA.DeleteCommand.Transaction = Tran
MasterTA.UpdateCommand.Transaction = Tran
MasterTA.InsertCommand.Connection = con
MasterTA.DeleteCommand.Connection = con
MasterTA.UpdateCommand.Connection = con
DetailsTA.InsertCommand = DetailsBuilder.GetInsertCommand
DetailsTA.UpdateCommand = DetailsBuilder.GetUpdateCommand
DetailsTA.DeleteCommand = DetailsBuilder.GetDeleteCommand
DetailsTA.InsertCommand.Transaction = Tran
DetailsTA.UpdateCommand.Transaction = Tran
DetailsTA.DeleteCommand.Transaction = Tran
DetailsTA.InsertCommand.Connection = con
DetailsTA.UpdateCommand.Connection = con
DetailsTA.DeleteCommand.Connection = con
MasterTA.Update(DS.Tables(0))
DetailsTA.Update(DS.Tables(1))
UpdateLedger(Tran)
Tran.Commit()
Return True
Catch ex As Exception
Tran.Rollback()
MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButton.OK, MessageBoxImage.Error)
Return False
Finally
con = Nothing
Tran = Nothing
End Try
End Function
I am using a CommandBuilder
if the Adpater 1 pass and the adapter 2 fail , I need to Re Fill my adapters again in order to avoid the concurrency violation . I CANNOT refill because I already have changes in the  DataTables I don't want the user to loose their information
and start writing them again.
 The FULL procedure is successfully executed if no Exception occur with in the try catch
I was able to eliminate the concurrency violation by  setting the
commandBuilder.ConfilctOption=ConflictOption.OverwriteChanges but this will fail to update the correct changes the 2nd time to the database
the only possible solution that I come  close to it. Before attempt to save anything
Is to copy the datatables
After update Fail Or Not
Clear the DataTables from the Dataset
Merge The dataTables from the DataSet with the Previous Copy Tables
Exception Occure (Violation of primary key constraint '.....' attempt to insert a duplicate key)
My IDS are not Auto Increment .
I Really really need to use a transaction with DataAdapters ,
I Also try the System.Transactions.TransactionScope
but I have 2 problems
Sometimes raise an error from the Server
It doesn't work always as it behaves almost the same as I describe the problems above (Works only The first time)
stelios ----------

this the StackTrace when the error is ExecuteReader requires the command to have....
 at System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
And this is the StackTrace for the error Concurrency Violation
   at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
stelios ----------

Similar Messages

  • Update multiple records with one submit?

    I can't for the life of me figure out how to do this. I have checkboxes with primary key id's listed as the value in a repeat region. I want to perform an update on 2 columns for all id's checked.
    SUDEO CODE
    <form>
    <cfoutput query ....
    other textfields...
               <input name="checkbox" type="checkbox" id="checkbox" value="#table.id#" />
    </cfoutput>
    SUBMIT BUTTON
    </form>
    My update statement:
    UPDATE table
    SET column1 = 1, column2 ='whatever'
    WHERE id IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#TRIM(FORM.checkbox)#">)
    </cfquery>
    It only updates if I check one box, does nothing when more than one is selected.
    I also tried looping over the update statement but nothing seems to work.

    You were missing the list attribute to cfqueryparam (you can also
    replace the cfif with a null attribute on the cfqueryparam but it has
    the disadvantage of sending the query to the db: null="#Not
    Len(Trim(form.checkbox))#").
    <cfif Len(Trim(form.checkbox))>
    <cfquery ...>
    UPDATE table
    SET column1 = 1, column2 = 'whatever'
    WHERE id IN (<cfqueryparam cfsqltype="cf_sql_integer"
    value="#form.checkbox#" list="true">)
    </cfquery>
    </cfif>
    Mack

  • Update multiple firewalls with one TFTP download

    Good evening, forum participants!
    I'm in a bit of a conundrum and need to ask the group a question:
    I need to update 21 firewalls that a previous consultant-vendor hasn't updated in several major versions.  The previous vendor didn't feel it important to maintain a current contract license on any of those firewalls to be able to update the software.  I don't want to purchase 21 service contracts in order to be able to update all the firewalls.
    Can I purchase one contract so I can download all of the versions of the software needed and use that software to update every firewall?  I just want to download once to my TFTP server and be done.  Is that possible?
    Your reply and quick response is greatly appreciated!
    Thanks!
    -Ed

    Hello,
    Can you let us know what is the model number of the devices? I'm just asking because, on the Small Business devices, you DO NOT need a contract to download any firmware version, they are all readily available for anyone to download with or without a contract.
    Please let us know.

  • Updating multiple devices with one download

    Hi all,
         I have two iPods that need updating. Can I download the update once to update both devices?
    Thanks

    Welcome to the Apple Community.
    Ideally you should each have your own iCloud account, that way you can each manage your own mail, contacts, calendars, documents etc and avoid unintentional deletions and unwanted editing. If there is information you wish to share between you, this can be done with a secondary account.
    Having separate iCloud accounts, doesn't mean you have to have separate iTunes accounts, so whilst you keep your personal data separate, you can continue to share music, apps, books, TV shows, movies etc.

  • Insert multiple rows with one sql statement in access

    Hi,
    I'm trying to copy a table into another. What I want to do is to use "Insert into table1 select * from table2 where field > val". Something like that. I know a lot of databases support it. I was wondering if ms access ODBC driver also supports it. I searched quite a bit and haven't found a definitive answer on this.
    Thank you

    Yes, M$ Access 2000 supports it. This is from their help:
    INSERT INTO Statement
    Adds a record or multiple records to a table. This is referred to as an append query.
    Syntax
    Multiple-record append query:
    INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
    SELECT [source.]field1[, field2[, ...]
    FROM tableexpression
    Single-record append query:
    INSERT INTO target [(field1[, field2[, ...]])]
    VALUES (value1[, value2[, ...])
    The way you've written the INSERT, table1 and table2 have to have the same # of columns and the same types, of course.

  • Advise on using DBMS_XA with multiple branches under one global transaction

    Dear all
    I need some advise on using DBMS_XA from PL/SQL with tightly coupled multiple branches under one global transaction. Basically, I've successfully written some PL/SQL code that in 3 different sessions attaches to 3 different branches of one global transaction and before ending each branch they can see each others uncommitted data. So far so good.
    However, I'm not sure I completely understand how each branch must call xa_end, xa_prepare and xa_commit correctly using two phase commit and my calls result in errors like:
    ORA-24767: transaction branch prepare returns read-only (XA error code 3 = Transaction was read-only and has been committed)
    ORA-24756: transaction does not exist (XA error code -4 = XID is not valid)
    ORA-02051: another session or branch in same transaction failed or finalized
    This is the structure of my programs (3 SQL*Plus sessions):
    main: Uses xid 123|0 (branch 0 of global transaction 123). This should be the coordinator that commits using two phase commit across the 3 branches
    m1.xa_start tmnoflags
    m2.DML
    m3.Wait for thread A + B to manually be started and run xa_end
    m4.xa_end tmsuccess
    m5.xa_prepare
    m6.xa_commit false
    thread A: Uses xid 123|A (branch A of global transaction 123)
    a1.xa_start tmnoflags
    a2.DML -- thread A can see main and thread B's data
    a3.xa_end tmsuccess
    a4.xa_prepare -- required?
    a5.Should we also call xa_commit false?
    thread B: Uses xid 123|B (branch B of global transaction 123)
    b1.xa_start tmnoflags
    b2.DML -- thread B can see main and thread A's data
    b3.xa_end tmsuccess
    b4.xa_prepare -- required?
    b5.Should we also call xa_commit false?
    The failing steps are:
    m5
    m6
    a4
    a5
    b4
    b5
    Before starting calling xa_end I see 3 rows in V$GLOBAL_TRANSACTION, eg (hex 7B = decimal 123):
    FORMATID GLOBALID BRANCHID BRANCHES REFCOUNT PREPARECOUNT STATE FLAGS COUPLING
    203348753 0000007B 00000000000000000000000000000000 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    203348753 0000007B 0000000000000000000000000000000A 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    203348753 0000007B 0000000000000000000000000000000B 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    Thanks a lot in advance.
    Cheers
    Finn

    OK, I've figured it out. This is poorly documented as it's not well explained how to handle the various return codes. Turns out that all but the last xa_prepare calls return dbms_xa.xa_rdonly (tightly coupled branches are combined -- "read only" optimization), the last one returns dbms_xa.xa_ok and this is when you should call xa_commit.
    Now my next problem is that DBMS_XA doesn't work from within jobs (DBMS_JOB and DBMS_SCHEDULER), which makes it very difficult to use DBMS_XA. My purpose of using DBMS_XA is to coordinate work across multiple sessions in one transaction but if I can't easily create the multiple sessions, I'm stuck.
    When called from a job, xa_start throws:
    ORA-24789: start not allowed in recursive call
    on Oracle 11.2. In Oracle 11.1 it works, but xa_end fails with
    ORA-25352: no current transaction
    so I guess in fact the xa_start call didn't really work either, even though it returned tm_ok.
    I'm now trying to find a workaround on how to use DBMS_XA from within jobs, please comment if you have any suggestions. Or if you have any suggestions on other means of establishing the concurrent sessions (I wouldn't like to resort to external programs that need username/password to connect as password management would be a security issue).
    Thanks in advance.
    Cheers
    Finn

  • Create multiple folders with one click on documents tab in BP in SAP CRM

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

  • Updating multiple rows with different values

    Hi!
    I have a problem. I need to update more then 1000 rows with different values. How can I do it?
    For exsample i have table:
    id; color, date,
    1 red
    2 green
    3 white
    I need to update date field.
    Update table
    set date='01.02.03'
    where id=1
    Update table
    set date='01.03.03'
    where id=2
    Maybe there is way how to update multiple rows at one query?
    Sorry for my bad english.
    Thanks!

    Hi,
    You can try this
    UPDATE TABLE SET DATE = CASE
                        WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
                        WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
                        ENDcheers
    VT

  • Update multiple records on one page php/mysql

    Hi folks,
    I am trying to adapt a page to offer the option to update multiple records on one page.
    The intention is to edit FAQ categories which are contained in a table with just two fields - the category and an id.
    The page lists each categories in a form with a submit button which is then repeated for each record in the recordset.
    Unfortunately my plan didn't work and only the first record updates as intended.
    Can anyone suggest how I can make it work?
    Here's the code I have so far.
    ************** The Update Code *****************
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    if (!isset($mm_abort_edit) || !$mm_abort_edit) {
    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
      $updateSQL = sprintf("UPDATE faq_categories SET category=%s WHERE id=%s",
                           GetSQLValueString($_POST['category'], "text"),
                           GetSQLValueString($_POST['id'], "int"));
      mysql_select_db($database_con_mysite, $con_mysite);
      $Result1 = mysql_query($updateSQL, $con_mysite) or die(mysql_error());
      $updateGoTo = "faq-category-edit.php
      if (isset($_SERVER['QUERY_STRING'])) {
        $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
        $updateGoTo .= $_SERVER['QUERY_STRING'];
      header(sprintf("Location: %s", $updateGoTo));
    ************** Update Code Ends *****************
    ************** The Form *****************
    <form name="frm_editcategory" id="frm_editcategory" method="POST" action="<?php echo $editFormAction; ?>">
      <?php do { ?>
    <fieldset>
              <input name="id" type="hidden" value="<?php echo $row_rs_faqcategory['id']; ?>" />
              <input name="category" type="text" class="formrightcolumn"  value="<?php echo $row_rs_faqcategory['category']; ?>" />
              <input name="save" type="submit" class="submitbutton" id="save" value="save" />
    </fieldset>
              <input type="hidden" name="MM_update" value="form1" />
       <?php } while ($row_rs_faqcategory = mysql_fetch_assoc($rs_faqcategory)); ?>
    </form>
    ************** The Form Ends *****************
    Cheers
    Dave

    What does debugging tell you? What's the value of each of the variables? Did you try using regular echo statements to monitor what's going on? That's what I always do whenever I am stuck in my PHP coding.

  • Multiple iPhones with one one computer

    I was using multiple iPhones with one one computer, each iPhone device has it's Owen Apple ID. When I connected my device. I got my mothers photos, contacts &amp; applications. All my applications are deleted, is there a way to retrieve my iPhones photos and applications ?

    Sign out of your mom's account in itunes, then sign in with your account, then restore your phone from your itunes backup.

  • Multiple selections to multiple layers or multiple files with one go ?

    Hi,
    how to convert multiple selections to multiple layers or multiple files with one go ?
    Thanks!

    You may want to ask over at
    http://forums.adobe.com/community/photoshop/photoshop_scripting?view=discussions
    or
    http://ps-scripts.com/bb/
    I think there are Scripts about for the task or at least ones that could be adapted without too much problems.
    The usual approach is, I think, creating a Work Path from a Selection and then using (expanded) Selections based on the individual subPathItems to intersect with the original selection.
    Of course there are possibilities for bad results …

  • Photoshop crashes while using multiple windows with one image

    Has anyone else encountered the following problem:
    Photoshop CS4 crashes sooner or later when working with multiple windows with one image (window->arrange->new window for...).
    I remember having same problem since CS2. Is this a bug in Photoshop or am I having a bad luck?
    Technical specifics:
    Ps CS4, iMac, 21.5, 10.6

    Don't know.  I haven't heard of other people having that problem.
    Do you have a crash report I could look at?
    Or have you attached your email to crash reports sent to Adobe and can you tell me the date on one of them?

  • Create multiple delivery with one invoice

    Hi all,
    can you tell me how to do multiple delivery with one invoice,
    i tried in vf01 by giving their my 3 delivery nos but it is generating three invoices
    pls explain this in details
    points will be rewarded
    regards,
    smmmmmm

    Dear Sameer
    As per your requirement run the Tcode VF04 (Billing Due list) and select the Delivery Documents for which you want to to have single Billing Document by clicking on Collective Billing document/Online  Push Button in that screen.
    To Have Single Billing Document for Multiple Delivery you need to have Payer,Terms of Payment,Incoterms(part 1 and part2) same for all materials orelse the billing document will split and this split analysis is visible during creating of Billing document.
    Hope this will help you in solving your problem.
    Regards
    PSH

  • Select or deselect multiple rows with one single selection  event

    Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
    row1
    row2
    row3
    row4
    row5
    row6
    What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
    For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
    Hopefully someone can give me a hint.

    Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
         private void addLineToList() {
              String a = f_one.getText();
              String b = f_two.getText();
              if (a.length() == 0) {
                   Utils.showInformationMessage("Item field is empty.");
                   f_one.requestFocusInWindow();
                   return;
              if (b.length() == 0) {
                   Utils.showInformationMessage("Match field is empty.");
                   f_two.requestFocusInWindow();
                   return;
              model.addElement("item: " + a);
              model.addElement("match: " + b);
              model.addElement(" ");
              int size = model.getSize();
              pairList.setSelectedIndex(size - 3);
              f_one.setText("");
              f_two.setText("");
              f_one.requestFocusInWindow();
         private void editList() {
              if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
                   Toolkit.getDefaultToolkit().beep();
                   f_one.requestFocusInWindow();
                   return;
              if (!f_one.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Item field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   OptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              if (!f_two.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Match field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   JOptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              String item = "";
              String match = "";
              int index = pairList.getSelectedIndex();
              String choice = model.getElementAt(index).toString();
              if (choice.startsWith("item")) {
                   item = choice;
                   match = model.getElementAt(index + 1).toString();
                   model.remove(index);
                   model.remove(index);
                   model.remove(index);
              else {
                   item = model.getElementAt(index - 1).toString();
                   match = choice;
                   model.remove(index + 1);
                   model.remove(index);
                   model.remove(index - 1);
              int size = model.getSize();
              if (size > 2) {
                   pairList.setSelectedIndex(size - 2);
              f_one.setText(item.substring(6));
              f_two.setText(match.substring(7));
              f_one.requestFocusInWindow();
         }

  • Once again:  Does MySQL allow multiple querys in one database transaction???

    Hello to ALL!!!
    The problem is:
    I'm trying to make simple query (database: "myDB" (engine:
    myisam/innodb - doesn't mater) with one table: "Info" with two
    columns: "Id" (autoinc), "info_c" (varchar):
    <cfif structkeyexists (form, "name")>
    <cfquery datasource="myDB" name="qDB" >
    INSERT into Info (info_c)
    VALUES ('#form.name#');
    SELECT @@identity AS Id
    </cfquery>
    </cfif>
    <cfform>
    <cfinput type="text" name="name">
    <cfinput type="submit" name="submit">
    </cfform>
    BUT after "Submit" I get:
    Error Executing Database Query.
    You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to
    use near '; select @@identity as Id' at line 2
    Please, tell me WHY???
    I have:
    MySQL
    Server information:
    MySQL version: MySQL 5.1.25-rc-community via TCP/IP
    Clent Information:
    Version: MySQL client version 5.1.11
    Coldfusion Version Information:
    Version 8,0,0,176276
    Great THANKS for your answers!!!

    > SELECT @@identity AS Id
    AFAIK, MySQL uses LAST_INSERT_ID(). @@IDENTITY is MS SQL
    specific. Though SCOPE_IDENITY() is recommended over @@IDENTITY.
    What version of CF are you using? ColdFusion supports the
    "result" attribute, which will return the ID value for simple
    inserts. See the documentation for details
    http://livedocs.adobe.com/coldfusion/8/Tags_p-q_17.html
    > Do JDBC drivers for MySQL prohibit the use of multiple
    queries
    > in a single database transaction???
    For security purposes this is disabled by default. To enable
    it you must modify your datasource url
    http://www.petefreitag.com/item/357.cfm

Maybe you are looking for

  • Problem with sound in games

    Hi all welcome as you can see I'm new to your forum. So I have a problem as it concerns the sound in games. Namely, I bought a Creative Headset HS-800 Fatality everything good in listening to music, etc. But when I go to the game, I turned the sound

  • R12: Discount on Payables Invoice (Functional)

    Hi all, I have a scenario involving discount on the purchase of an Item. My invoice, as received as the supplier is as follows: $ Item xxx 100 Discount (10) Total 90 VAT(15%) 15.50 Net 103.50 When I create an invoice in AP, I add a line with amount $

  • Does this Performance Tunning course apply to OCP?

    Hello, I'm planning to get Database OCP exam soon, and I was wondering if this course (Certificacion prerequisite) can apply to get this Certification, D50317GC20 - Oracle Database 11g: Performance Tuning DBA Release 2 (http://education.oracle.com/pl

  • Web Page error after install

    I finished installing OBIEE 10.1.3.3 with no errors. I used the Basic installation using IIS on one server. After finishing the install and restarting the server, all services are started but I get the following when I try to access the http://localh

  • Why can't I download the latest Ipod software?

    I have attempted several times to download the updated software for my ipod through itunes, but everytime I try I get the message "the download has been cancelled, your connection timed out". What does this mean and how can I get the update? Thank yo