sqltransaction

Executing a stored procedure inside BEGIN/END TRANSACTION

不问归期 提交于 2019-11-28 18:11:54
If I create a Stored Procedure in SQL and call it ( EXEC spStoredProcedure ) within the BEGIN/END TRANSACTION, does this other stored procedure also fall into the transaction? I didn't know if it worked like try/catches in C#. Yes, everything that you do between the Begin Transaction and Commit (or Rollback) is part of the transaction. Miles Sounds great, thanks a bunch. I ended up doing something like this (because I'm on 05) BEGIN TRY BEGIN TRANSACTION DO SOMETHING COMMIT END TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK -- Raise an error with the details of the exception DECLARE @ErrMsg

Does SqlTransaction need to have Dispose called?

让人想犯罪 __ 提交于 2019-11-28 03:48:39
问题 Do I need to call dispose in the finally block for SqlTransaction? Pretend the developer didnt use USING anywhere, and just try/catch. SqlTransaction sqlTrans = con.BeginTransaction(); try { //Do Work sqlTrans.Commit() } catch (Exception ex) { sqlTrans.Rollback(); } finally { sqlTrans.Dispose(); con.Dispose(); } 回答1: Do I need to use try-finally or the using -statement to dispose the SqlTransaction ? It does not hurt to have it. This is true for every class implementing IDisposable, otherwise

SQL Server : is there any performance penalty for wrapping a SELECT query in a transaction?

强颜欢笑 提交于 2019-11-28 02:19:11
As learning exercise and before trying to use any ORM (like EF) I want to build a personal project using ADO.NET and stored procedures. Because I don't want my code to become a mess over time, I want to use some patterns like the repository and UoW patterns. I've got almost everything figured it out, except for the transaction handling. To somehow 'simulate' a UoW, I used this class provided by @jgauffin, but what's stopping me from using that class is that every time you create a new instance of that class ( AdoNetUnitOfWork ) you're automatically beginning a transaction and there a lot of

how to use sqltransaction in c#

大城市里の小女人 提交于 2019-11-27 20:35:15
I am using following code to execute two commands at once. I used sqltransaction to assure either all command get executed or rolled back.When I run my program without "transaction" it run properly but when I use "transaction" with them they show error. My code is as follow; SqlTransaction transaction = connectionsql.BeginTransaction(); try { SqlCommand cmd1 = new SqlCommand("select account_name from master_account where NOT account_name = 'BANK' AND NOT account_name = 'LOAN'", connectionsql); SqlDataReader dr1 = cmd1.ExecuteReader(); while (dr1.Read()) { comboBox1.Items.Add(dr1[0].ToString()

Executing a stored procedure inside BEGIN/END TRANSACTION

落花浮王杯 提交于 2019-11-27 10:44:57
问题 If I create a Stored Procedure in SQL and call it ( EXEC spStoredProcedure ) within the BEGIN/END TRANSACTION, does this other stored procedure also fall into the transaction? I didn't know if it worked like try/catches in C#. 回答1: Yes, everything that you do between the Begin Transaction and Commit (or Rollback) is part of the transaction. 回答2: Sounds great, thanks a bunch. I ended up doing something like this (because I'm on 05) BEGIN TRY BEGIN TRANSACTION DO SOMETHING COMMIT END TRY BEGIN

SQL Server : is there any performance penalty for wrapping a SELECT query in a transaction?

自闭症网瘾萝莉.ら 提交于 2019-11-26 23:41:23
问题 As learning exercise and before trying to use any ORM (like EF) I want to build a personal project using ADO.NET and stored procedures. Because I don't want my code to become a mess over time, I want to use some patterns like the repository and UoW patterns. I've got almost everything figured it out, except for the transaction handling. To somehow 'simulate' a UoW, I used this class provided by @jgauffin, but what's stopping me from using that class is that every time you create a new

how to use sqltransaction in c#

吃可爱长大的小学妹 提交于 2019-11-26 20:25:57
问题 I am using following code to execute two commands at once. I used sqltransaction to assure either all command get executed or rolled back.When I run my program without "transaction" it run properly but when I use "transaction" with them they show error. My code is as follow; SqlTransaction transaction = connectionsql.BeginTransaction(); try { SqlCommand cmd1 = new SqlCommand("select account_name from master_account where NOT account_name = 'BANK' AND NOT account_name = 'LOAN'", connectionsql)