Re: DbProviderFactory and transactions.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Luigi,

See inline:

- I need to insert data in the first if not present

Using transactions if when I check I see I can proceed to insertion and
another concurrent access arrives before my insertion, I'll get an
exception as soon as I do executeNonQuery?

You won't have an exception. If you have a serializable transaction and
you are inserting the record into the database, the other transaction that
tries to perform an operation will block until you are done with the first
transaction.

If you are looking to update this data in the event that the record is
already inserted, then you should select the data out first (or do something
to obtain the lock) and then if you get any rows back, perform an update,
otherwise, perform an insert.

- I need to do noop if I'm trying to insert data in all the tables and one
field has the same value of that in the data I want to insert

How can I check this at the moment of insertion?
Maybe I've to create a good SQL query with a select in the where clause of
an insert?

Why bother? If you are performing an update, and the fields that you
are updating are the same as the fields that are already there, then its the
same thing as a no-op. There is no reason to check every field in the
table.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


.



Relevant Pages

  • Re: Detecting that a row has been updated.
    ... You can compare ROWVERSION for the specific data like client applications connects to the database and returns some data, then it performs some operations for example and when you are ready to commit the transaction, compare a row versuion of your old and new before commiting a transaction, so if they are different someone updated that row ... With the insertion it is possible to define a default, can something similar be done with updating? ... Triggers would be a possibillity, but I would prefer a default which get 'pasted' during the update and not use triggers. ...
    (microsoft.public.sqlserver.server)
  • Re: Concurrent Database Maintenance?
    ...    holes in the existing pages, which mainly contain older transaction data, ... This is rare in the real world. ... Such random (relative to the insertion ...
    (comp.databases.informix)
  • Re: dbms_transaction.local_transaction_id in triggers
    ... in one single transaction I have to do some ... To address this requirement I am planning to use ... Means on update trigger executes and does insertion in some ... reset package variable at the end of the transaction. ...
    (comp.databases.oracle.server)
  • SqlConnection and Transaction
    ... SqlCommand after I start a transaction. ... If I have convertion error for the insertion of the data, ... "The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION" ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: You wanted defensive writing...
    ... Couldn't you have set the debugger to break on all exceptions? ... > I've created an application that loads Caudill's TreeListView as its ... > I commented the line that called the insertion on start-up, ... > The exception caught me unaware, ...
    (microsoft.public.dotnet.csharp.general)