Questions tagged [sqltransaction]

An SQL-transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order. Executing SQL-statements in Transactions, can ensure data integrity and handle database errors.

An SQL-transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order.

A transaction is the propagation of one or more changes to the database. For example, creating, updating, or deleting a record from the table. Transactions are used to ensure data integrity and to handle database errors, by collecting SQL queries into a group and executing all of them together, as one unit of work.

Properties of Transactions: Transactions have the following four standard properties, usually referred to by the acronym ACID:

  • Atomicity: ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state.
  • Consistency: ensures that the database properly changes states upon a successfully committed transaction.
  • Isolation: enables transactions to operate independently of and transparent to each other.
  • Durability: ensures that the result or effect of a committed transaction persists in case of a system failure.
233 questions
2
votes
1 answer

Strange behavior with List.ForEach(Action) and a Sql Transaction

Scenario I'm writing a system to carry out exams. The person in charge of the exam (Invigilator) starts the exam, and at that point, the people taking the exam (Candidates) are permitted to start. If a candidate tries to start prematurely they…
Jack Pettinger
  • 2,715
  • 1
  • 23
  • 37
2
votes
1 answer

Manage concurrency in SQL Server

I have a table in my SQL Server database which contains some data about books like the given screenshot below: +----+-------+-------+--------+ | Id | Title | Price | Status | +----+-------+-------+--------+ | 1 | C#6 | 40.00 | 0…
Ahmed Negm
  • 865
  • 1
  • 11
  • 30
2
votes
2 answers

SQL Server : Identity column by group

How can I add an identity number so that when a row is inserted an incremental number is assigned as below by a trigger? I am using SQL Server. 1 AAA 2 AAA 3 BBB 4 CCC 5 CCC 6 CCC 7 DDD 8 DDD 9 EEE …
Mansoor
  • 31
  • 1
  • 8
2
votes
0 answers

SMO transaction failing via C# code

We have bunch of SQL script files that we are trying to execute via C# code. Scenarios: We want to execute all the script files on SQL Server. If successfully executed all scripts then commit the transaction else rollback everything. If file…
Amnesh Goel
  • 2,617
  • 3
  • 28
  • 47
2
votes
0 answers

SQLtransactions inside TransactionScope

I have a sql transaction inside a transactionscope and that transaction is doing a commit or a rollback. But from what I've read, that commit/rollback will have no meaning as it's controlled by the transactionscope. However if I leave the…
Baahubali
  • 4,604
  • 6
  • 33
  • 72
2
votes
1 answer

TransactionScope with nested sql transactions

I have inherited a code that is executing 5 different stored procedures which are updating in the back-end and each have their own transaction object. i wrapped all 5 sql transactions within the transaction scope object as they all need to commit…
Baahubali
  • 4,604
  • 6
  • 33
  • 72
2
votes
3 answers

multiple sqltransactions in single sqlconnection

I have some code that I want to execute as follows. But I keep getting the exception "This SqlTransaction has completed; it is no longer usable" on the 2nd iteration. Could someone help me point out what I am doing wrong here? Thanks! …
EndlessSpace
  • 1,320
  • 2
  • 24
  • 46
2
votes
2 answers

SQLITE: stop execution if select returns specific value

Is there any way to write an SQL input file for sqlite that would somehow "throw" an error, eg. exited the transaction with rollback, if a condition isn't met? I have a script that is supposed to do something, but only if there is a certain row in…
Petr
  • 13,747
  • 20
  • 89
  • 144
2
votes
1 answer

SQL trigger compiling but I get an error

I created a trigger in SQL and it compiles ok but when I run an insert it I get the following error: SQL Error: ORA-01403: no data found ORA-06512: at "EOCRIBIN.SHIPMENT_CAPACITY", line 5 ORA-04088: error during execution of trigger…
Eoin Ó Cribín
  • 155
  • 1
  • 3
  • 14
2
votes
1 answer

Is it possible to debug visual studio to view SqlConnection transactions

I'm currently getting an error message in my asp.net application as an SQLCommand transaction is being committed, and I can't see how it is happening. The error message states: Cannot insert the value NULL into column 'SectorID', table…
e-on
  • 1,547
  • 8
  • 32
  • 65
2
votes
1 answer

Will SqlBulkCopy Close method commit/Dispose external transaction?

I have a SQL Bulk copy function which has following code to create a bulk copy instance. SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection) WorkConnection, SqlBulkCopyOptions.FireTriggers, (SqlTransaction)…
Relativity
  • 6,690
  • 22
  • 78
  • 128
2
votes
2 answers

Commit multiple SqlCommands with SqlTransaction

I am trying to pass a list of SqlCommand into a member function that holds the connection to the database. public void CommitAsTransaction(List commands) { SqlTransaction transaction = null; SqlConnection connection = null; …
Hexadron
  • 58
  • 1
  • 4
2
votes
1 answer

How does SQLTransaction.Commit() work?

A few day ago, I have studied SqlTransaction and I know the purpose of SqlTransaction.Commit() - it should "commit the database transaction." - MSDN. But HOW DOES IT WORK? For example: I wrote a piece of code like this: using (SqlTransaction tran =…
GIANGPZO
  • 380
  • 2
  • 3
  • 21
2
votes
3 answers

Why might a SqlTransaction fail to commit when the commit function is called?

I'm running into an issue where changes made are being rolledback even when none of the queries throw an exception. It's strange since the code works in one environment but isn't committing changes in another. Here is the function that handles the…
Robert
  • 75
  • 9
2
votes
2 answers

Insert OUTPUT Insert.id to another table in multiple values insert

Just for simplicity suppose I have two tables user table (id, email) user log table (id, date) whatever id gets inserted in user table, same id should be inserted in user_log table also else transaction should fail. How can I do this BEGIN…
Sami
  • 3,926
  • 1
  • 29
  • 42