Hi,
The question is about how to check if the transaction is still active. Let's
say, that I am using a 3rd party stored procedure, that cannot be changed.
Sample is (Of course, the real one is much more complicated):
CREATE PROC test AS IF @@trancount > 0 ROLBACK TRAN
Now, I'm executing code:
tran = connection.Begi nTransaction();
cmd = new SqlCommand("tes t", connection);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.ExecuteNonQ uery();
After that - how do I know if the transaction is still active?
Regards 5 1431
For this same purpose, The Microsoft Data Access block checks to see if the
transaction.con nection is a valid connection or null.
- Sahil Malik http://dotnetjunkies.com/weblog/sahilmalik
"Piotr Strycharz" <Pi************ *@antispam-account.com> wrote in message
news:cp******** *@nemesis.news. tpi.pl... Hi,
The question is about how to check if the transaction is still active.
Let's say, that I am using a 3rd party stored procedure, that cannot be changed. Sample is (Of course, the real one is much more complicated): CREATE PROC test AS IF @@trancount > 0 ROLBACK TRAN
Now, I'm executing code:
tran = connection.Begi nTransaction(); cmd = new SqlCommand("tes t", connection); cmd.CommandType = CommandType.Sto redProcedure; cmd.ExecuteNonQ uery();
After that - how do I know if the transaction is still active?
Regards
"Piotr Strycharz" <Pi************ *@antispam-account.com> wrote in message
news:cp******** *@nemesis.news. tpi.pl... Hi,
The question is about how to check if the transaction is still active. Let's say, that I am using a 3rd party stored procedure, that cannot be changed. Sample is (Of course, the real one is much more complicated): CREATE PROC test AS IF @@trancount > 0 ROLBACK TRAN
Now, I'm executing code:
tran = connection.Begi nTransaction(); cmd = new SqlCommand("tes t", connection); cmd.CommandType = CommandType.Sto redProcedure; cmd.ExecuteNonQ uery();
You can examine the @@trancount. If it is > 0 then the transaction is
active. Otherwise the transaction has been rolled back.
new SqlCommand("sel ect @tc = @@trancount)
and bind an output parameter to @tc.
David
"Piotr Strycharz" <Pi************ *@antispam-account.com> wrote in message
news:cp******** *@nemesis.news. tpi.pl...
| Hi,
|
| The question is about how to check if the transaction is still active.
Let's
| say, that I am using a 3rd party stored procedure, that cannot be changed.
| Sample is (Of course, the real one is much more complicated):
| CREATE PROC test AS IF @@trancount > 0 ROLBACK TRAN
|
| Now, I'm executing code:
|
| tran = connection.Begi nTransaction();
| cmd = new SqlCommand("tes t", connection);
| cmd.CommandType = CommandType.Sto redProcedure;
| cmd.ExecuteNonQ uery();
|
| After that - how do I know if the transaction is still active?
|
| Regards
|
the commit will fail if no pending transaction exits - this will be your
fallback.
procs generally test @@trancount to avoid throwing an error on rollback when
there is no nested transction. you need to look to see how the proc is
returning failure - return value, raiserror, or paramter.
you are going to use multiple batches be sure to use the same connection,
and don't close it. at anytime you can select @@trancount to see a
transaction is active. you could also use the follow sp to do the commit.
create proc DoCommit as
set nocount on
if @@trancount > 0
begin
commit tran
select 1 as CommitResult
end
return 0 as CommitResult
then use
cmd = new SqlCommand("DoC omitt", connection);
cmd.CommandType = CommandType.Sto redProcedure;
bool ok = ((int) cmd.ExecuteScal er()) ==1);
-- bruce (sqlwork.com)
"Piotr Strycharz" <Pi************ *@antispam-account.com> wrote in message
news:cp******** *@nemesis.news. tpi.pl...
| Hi,
|
| The question is about how to check if the transaction is still active.
Let's
| say, that I am using a 3rd party stored procedure, that cannot be changed.
| Sample is (Of course, the real one is much more complicated):
| CREATE PROC test AS IF @@trancount > 0 ROLBACK TRAN
|
| Now, I'm executing code:
|
| tran = connection.Begi nTransaction();
| cmd = new SqlCommand("tes t", connection);
| cmd.CommandType = CommandType.Sto redProcedure;
| cmd.ExecuteNonQ uery();
|
| After that - how do I know if the transaction is still active?
|
| Regards
|
Użytkownik "bruce barker" <no***********@ safeco.com> napisał w wiadomo¶ci
news:Ob******** ******@tk2msftn gp13.phx.gbl... the commit will fail if no pending transaction exits - this will be your fallback.
Yes ! And it fails, indeed. However, my code is not aware of the ended
transaction, so it executes consecutive commands **without** transaction
(although transaction variable is not null).
Seems, that the @@trancount sql variable is the one solution.
Regards. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mahajan.sanjeev |
last post by:
I have two SQLConnection objects having the same connection string and
two corresponding SQLCommand objects for each connection object. I am
using SQLTransaction with the first SQLConnection object but the second
SQLConnection object does not have any SQLTransaction object.
I am inserting some data using the two command objects. The problem
happens when I try to do a rollback on the SQLTransaction object. The
rollback happens only before...
|
by: mahajan.sanjeev |
last post by:
Hi,
I am having problems with rollback using the SQLTransaction object. I
am trying to insert records in two tables in a transaction. I want to
rollback all the changes if any exception occurs in any of the inserts.
But the SQLTransaction object only rolls back the inserts that happen
before an exception. All inserts after the exception go through. What
am I doing wrong? Is it that I cannot do any more Inserts using the
transaction...
|
by: mahajan.sanjeev |
last post by:
Hi All,
I am using a SQLTransaction in a .Net application to insert records
into a SQL Server table. At one time, there are 5000 or more records to
be inserted one by one. It takes some 20-25 mins for the entire process
to run.
Another application accesses the same table.
As long as the insert process within the transaction isn't completed,
|
by: perspolis |
last post by:
Hi all
I used SqlTransaction inmy application..
SqlTransaction
transact=sqlConnection1.BeginTransaction(IsoLationLevel.Something);
sqlSelect.Transaction=transact;
sqlInsert.Transaction=transact;
,...............
but any of IsolationLevel stat I use it dosen't work properly and it works
as Serializable isolation level..
When I'm using a transaction for a master-slave tables and I want when
|
by: Junyin.Wu |
last post by:
what is difference between SqlTransaction and T-Sql(begin tran, commit
tran, rollback tran)
thanks.
| |
by: Joe Rigley |
last post by:
Hi All,
I am using a SqlTransaction object to process a group of database insert /
update statements on Sql Server 200 SP4 to complete a business process.
Directly after the Commit method is issued, I perform a select on one of the
tables that was inserted into during the SqlTransaction process.
Unfortunately, the select statement does not return any data that was just
inserted. I have checked the SQL statement syntax and it is valid....
|
by: Swami Muthuvelu |
last post by:
Hi,
I using command builder to generate my insert, update and
delete statements..something like,
data_adapter = New SqlClient.SqlDataAdapter(SQL,
ActiveConnection)
command_builder = New SqlClient.SqlCommandBuilder
(data_adapter)
|
by: samuelberthelot |
last post by:
Hello,
I have a asp.net application in which users can create content and
then save everything to a SQLServer2000 database.
When they hit the save button on the form here is what I do :
Dim conn As SqlClient.SqlConnection = New
SqlClient.SqlConnection( myconnectionstring )
Dim tx As SqlClient.SqlTransaction
conn.Open()
|
by: =?Utf-8?B?UGhpbCBKb2huc29u?= |
last post by:
Hi,
This is being called in a C# loop within an ado.net transaction from C# 1.1
code. It is used to write large file data to a SQL Server database in
chunks, rather than in one go.
I had the stored procedure below, which worked until the image datatype was
changed to varbinary(max).
Now I get the following error:
|
by: MrMancunian |
last post by:
Ok, I'm stuck on a design problem and I need some feedback how to go around it.
CASE:
Pathologists can request stains on certain tissues. It's possible to request more than one stain a time. The program where they make these requests (which is third-party software) creates an XML-file for one stain. So, if two stains are requested on one piece of tissue, it will create two XML-files. The program I'm writing needs to parse those XML-files,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |