473,586 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code works without transaction but not with transaction?


C#
VS 2003
..Net Framework V1.1 SP1
SQL Server 2000 SP3
Enterprise Library June 2005

I'm working with some code {not of my creation} that performs the
following sequence of actions:

- Open SqlConnection using SQL authentication with UID & PWD in connect
string
- BeginTransactio n
- Call stored procedure that updates 1 table {OK}
- Call stored procedure that updates 1 table {FAIL}
- Call stored procedure that updates 1 table
- Call stored procedure that updates 1 table
- Commit
- Dispose

All calls to the stored procedures are coded like this:

SqlHelper.Execu teNonQuery(tran saction,
CommandType.Sto redProcedure,
"StoredProcedur e",
param, param ...)

SYMPTOMS:

-If I take away the transaction the code works Ok
-If I use the transaction the code always fails on the second stored
procedure call with a "Login failed for user xxx" exception bubbled up
from ADO.NET's ConnectionPool. GetConnection() method
-If I shuffle the order of procedure calls the second call still always
fails
-If I put a breakpoint before the second procedure call the
transaction's connection is Open and the Isolation level is the default
{ReadCommitted}

As the natives were gathering outside my cube with pitchforks and
torches I hacked out the transaction and put something that works back
online. But, what the heck is happening - any ideas?

Feb 1 '06 #1
6 2216
Crash,

Well, you obviously have an error with the second stored procedure. You
need to track that down.

As for why everything fails, once there is a fail vote in the
transaction, SQL Server will not let you back it out. You have to redo the
whole thing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Crash" <so*********@sa n.rr.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...

C#
VS 2003
.Net Framework V1.1 SP1
SQL Server 2000 SP3
Enterprise Library June 2005

I'm working with some code {not of my creation} that performs the
following sequence of actions:

- Open SqlConnection using SQL authentication with UID & PWD in connect
string
- BeginTransactio n
- Call stored procedure that updates 1 table {OK}
- Call stored procedure that updates 1 table {FAIL}
- Call stored procedure that updates 1 table
- Call stored procedure that updates 1 table
- Commit
- Dispose

All calls to the stored procedures are coded like this:

SqlHelper.Execu teNonQuery(tran saction,
CommandType.Sto redProcedure,
"StoredProcedur e",
param, param ...)

SYMPTOMS:

-If I take away the transaction the code works Ok
-If I use the transaction the code always fails on the second stored
procedure call with a "Login failed for user xxx" exception bubbled up
from ADO.NET's ConnectionPool. GetConnection() method
-If I shuffle the order of procedure calls the second call still always
fails
-If I put a breakpoint before the second procedure call the
transaction's connection is Open and the Isolation level is the default
{ReadCommitted}

As the natives were gathering outside my cube with pitchforks and
torches I hacked out the transaction and put something that works back
online. But, what the heck is happening - any ideas?

Feb 1 '06 #2

I switched the order of the procedure calls around - it doesn't matter
what order I call them in the second one always fails. If I remove the
transaction all of the procedure calls succeed...

What disturbs me is that I am in the middle of performing steps in an
active transaction on an open connection - and the exception is
bubbling up from the connection pool???? Why would it try to fetch a
connection from the pool while I'm in the middle of a transaction????

Feb 1 '06 #3

I forgot to add:

The transaction is NOT distributed - all stored procedures are
executing in the same database...

Feb 1 '06 #4
On 1 Feb 2006 14:44:00 -0800, Crash wrote:

C#
VS 2003
.Net Framework V1.1 SP1
SQL Server 2000 SP3
Enterprise Library June 2005

I'm working with some code {not of my creation} that performs the
following sequence of actions:

- Open SqlConnection using SQL authentication with UID & PWD in connect
string
- BeginTransactio n
- Call stored procedure that updates 1 table {OK}
- Call stored procedure that updates 1 table {FAIL}
- Call stored procedure that updates 1 table
- Call stored procedure that updates 1 table
- Commit
- Dispose

All calls to the stored procedures are coded like this:

SqlHelper.Exec uteNonQuery(tra nsaction,
CommandType.Sto redProcedure,
"StoredProcedur e",
param, param ...)

SYMPTOMS:

-If I take away the transaction the code works Ok
-If I use the transaction the code always fails on the second stored
procedure call with a "Login failed for user xxx" exception bubbled up
from ADO.NET's ConnectionPool. GetConnection() method
-If I shuffle the order of procedure calls the second call still always
fails
-If I put a breakpoint before the second procedure call the
transaction' s connection is Open and the Isolation level is the default
{ReadCommitted }

As the natives were gathering outside my cube with pitchforks and
torches I hacked out the transaction and put something that works back
online. But, what the heck is happening - any ideas?


Hi Crash,

Since it's always the second procedure that fails, regardless of the
order of execution, I suspect that the stored procedures somehow mess up
the transaction nesting level. Maybe they start a transaction that they
don't end, or maybe they end (commit/rollback) the open transaction that
the next procedure expects to be still open?
What happens if you execute a script like the one below from Query
Analyzer:

BEGIN TRANSACTION
EXEC Proc1 param, param, ...
EXEC Proc2 param, param, ...
EXEC Proc3 param, param, ...
EXEC Proc4 param, param, ...
COMMIT TRANSACTION

Do all procedures execute or do you get errors? If the latter, please
copy and paste the error messages.

It might also help to post the code of the stored procedures themselves.

--
Hugo Kornelis, SQL Server MVP
Feb 2 '06 #5

- FYI this code is running under ASP, but it is logging into the
database as a specific user. The user that ASP logs in as is not dbo
but does have rights on all of the tables & procedures involved {I
checked}...

- None of the tables involved have any triggers on them {I checked}...

- The entire database has no indexes, no constraints, or any other of
those pesky referrential integrity nuisances {not the way I'd do it
either but I got called in to help on this one}...

- Forgot to mention it earlier but had already tried it - yes - within
query analyzer I can succesfully execute any combination of sproc calls
within a transaction just as you recommended... No errors from Query
analyzer within a transaction no matter what order of execution...

- None of the stored procedures does anything with transactions in and
of themselves - they each insert or update 1 row in a single table per
call... The stored procedures do different things but here's a look at
one of them:

CREATE PROCEDURE dbo.WT_UserInfo _Update
(

@UserID int =Null,
@Password varchar(64) = NULL,
@FirstName varchar(30) = NULL,
@LastName varchar(30) = NULL,
@JobTitle varchar(100) = NULL,
@PhoneNumber varchar(50) = NULL,
@EmailAddress varchar(100) = NULL,
@AdminUserID int = NULL

)
AS
BEGIN
--Update Existing User
Update WT_User
set Password=@Passw ord,
PasswordChangeD ate=getdate(),
FirstName=@Firs tName,
LastName=@LastN ame,
JobTitle=@JobTi tle,
PhoneNumber=@Ph oneNumber,
EmailAddress=@E mailAddress,
ModifiedBy= @AdminUserID
Where UserID=@UserID
IF @@ERROR <> 0 GOTO ExitProcError
return @UserID
END
ExitProcError:
Return(-1)

GO

SET QUOTED_IDENTIFI ER OFF
GO
SET ANSI_NULLS ON
GO

GRANT EXECUTE ON [dbo].[WT_UserInfo_Upd ate] TO [<<same user as used
in connect string>>]
GO

The other procedures do not do anything fancier; 1 deletes from a
{different} table where @UserID=xxx, and a third procedure is called x
times to insert 1 row into the other table per call.

I'm thinking this is more of an ADO issue of some sort, but it is
bizarre. Flawlessly reproducable, but very bizarre...

Feb 3 '06 #6
On 3 Feb 2006 11:50:06 -0800, Crash wrote:

- FYI this code is running under ASP, but it is logging into the
database as a specific user. The user that ASP logs in as is not dbo
but does have rights on all of the tables & procedures involved {I
checked}...

- None of the tables involved have any triggers on them {I checked}...

- The entire database has no indexes, no constraints, or any other of
those pesky referrential integrity nuisances {not the way I'd do it
either but I got called in to help on this one}...

- Forgot to mention it earlier but had already tried it - yes - within
query analyzer I can succesfully execute any combination of sproc calls
within a transaction just as you recommended... No errors from Query
analyzer within a transaction no matter what order of execution...

- None of the stored procedures does anything with transactions in and
of themselves - they each insert or update 1 row in a single table per
call... The stored procedures do different things but here's a look at
one of them:
(snip)
The other procedures do not do anything fancier; 1 deletes from a
{different} table where @UserID=xxx, and a third procedure is called x
times to insert 1 row into the other table per call.

I'm thinking this is more of an ADO issue of some sort, but it is
bizarre. Flawlessly reproducable, but very bizarre...


Hi Crash,

Yeah, I have to agree. Since a logically identical series of statements
from Query Analyzer executes flawlessly, it's probably not a SQL Server
issue.

I have no ADO experience, so I can't help you further. Maybe you should
take this to an ADO group. (I think they'll want to see more of the
front--end code than you posted here, though).

--
Hugo Kornelis, SQL Server MVP
Feb 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1691
by: J Dubal | last post by:
Hello good people, Following works in FC1 (python-2.2.3-7, postgresql-7.3.4-11, kernel-2.4.22-1.2194.nptl, pyPgSQL-2.4) from pyPgSQL import PgSQL conn = PgSQL.connect('localhost',database='rop') loccur = conn.cursor() loccur.execute("DECLARE itemcursor CURSOR FOR \ SELECT * FROM locmf")
242
13286
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on...
14
24214
by: David Blickstein | last post by:
I have some XML documents that I want to open in a web browser and be automatically translated to HTML via XSLT. I'm using an xml-stylesheet processing command in a file called "girml.xml". This all works in Internet Explorer, but doesn't work with Firefox. In both IE and Firefox this works: <?xml-stylesheet type="text/xsl"...
5
2461
by: David Deacon | last post by:
Hi i was given the following advise,below my OriginalQuestion I am a little new to ADOX can you direct me to the following Do i place the code behind a button on a form? Or do i place it in the On Open event and have a the default 10% and give the user the option to change it to 0% I have referenced th appropriate library and the default...
1
1506
by: JBD | last post by:
Hi, I have a button that fires the below sub routine. This works fine if the user clicks the button as they are supposed to, even if they click it repeatedly. However, if you click "refresh" on the browswer, then it duplicates records. I believe this is happening because somehow it isnt doing the first part of my code which is to to an...
18
3147
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the...
2
2478
by: Ben | last post by:
Hi, One ASP.NET transactional page conducts a long transaction in a button click function. I want to display the transaction progress info in label control without refreshing page. It is because page refreshing will commit the transaction automatically. How to do it?
232
13195
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an...
1
1548
by: Jan | last post by:
Hi: I've been tearing my hair out over this one for a few days; did a search of the archives and found similar questions but no real answers. Here goes: This is an application for a retail store. There are transactions, transaction details, and then, depending on the type of detail, related records in other tables. So when I'm entering...
0
8204
Oralloy
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. ...
0
8339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7965
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
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...
1
5712
isladogs
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...
0
5392
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.