Solved

Transaction context in use by another session.  Error

Posted on 2003-11-20
10
1,747 Views
Last Modified: 2007-12-19
I have an ASP page that creates a SQL statement in on the fly and puts it in a string variable.  I then fill a recordset with the following code:

set rst = conCRep.Execute(sql)

The recordset is filled with about 750 records, and there is only one field per record.  At this point, I loop through the recordset as follows:

Do While Not rst.Eof

     sql = "SELECT * FROM BankComp WHERE "
     sql = sql & "Program = '" & rst("ProgramNumber") & "' AND EffectiveDate = '" &  
             EffDate & "'"

    set rstTest = conCRep.Execute(sql)

     .....

     rst.MoveNext
Loop

The first time it tries to run the rstTest statement, I get the "Transaction context in use by another session." error.  Any ideas what is going wrong?  This only seems to happen when the initial SQL statement is returning a lot of records.  For the record I am running SQL Server 2000.
0
Comment
Question by:mattgoolsby
  • 4
  • 3
10 Comments
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
What Lock are you using? Can you show the code you use to actually access the database?
0
 

Author Comment

by:mattgoolsby
Comment Utility
I simply am opening a connection to the DB at the top of the ASP page with this code:

Set conCRep = Server.CreateObject("ADODB.Connection")
conCRep.Open ConnectionString

The ConnectionString variable is as follows:

ConnectionString = "provider=SQLOLEDB;Data Source=(local);Initial Catalog=CoverdellReporting;User ID=xxxxxxxx;Password=xxxxxxxx"
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
Comment Utility
You may need to this as follows

'This may need to be outside the loop
sql = "SELECT * FROM BankComp WHERE "
     sql = sql & "Program = '" & rst("ProgramNumber") & "' AND EffectiveDate = '" &  
             EffDate & "'"
set rstTest = conCRep.Execute(sql)

' The sql here may return more than one row. Plus, without closing the current result set, news rows are retrieved into it.

Do While Not rst.Eof


     rst.MoveNext
Loop
0
 

Author Comment

by:mattgoolsby
Comment Utility
I do not think that is my problem.  In this particular case, the "set rst" statement returns 760 rows.  Each row has a ProgramNumber field and that's it.

I then need to loop through each of the 760 records.  At this point, I create the second SQL statement (set rstTest), which has to be inside the loop since it is using the ProgramNumber value.  "Program" and "EffectiveDate" is the primary key in the BankComp table, so only one row will ever be returned.

I ran my program where only 14 records were returned in the initial SQL statement, and it ran fine.  It seems to have a problem when it is large amounts of data.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 15

Expert Comment

by:namasi_navaretnam
Comment Utility
Actually, I did not notice that there are different result sets.

Try this,

Do While Not rst.Eof

     sql = "SELECT * FROM BankComp WHERE "
     sql = sql & "Program = '" & rst("ProgramNumber") & "' AND EffectiveDate = '" &  
             EffDate & "'"

    set rstTest = conCRep.Execute(sql)
    'Extract infomation you need.
     restTest.Close()
     .....

     rst.MoveNext
Loop
0
 

Author Comment

by:mattgoolsby
Comment Utility
The code errors out the first time through the "Do" loop.  As soon as it tries to run "set rstTest" for the first time is when I get the error.

Just to be sure, I added the "Close" statement, and that did not work.  It never even reaches that point before the error.
0
 

Author Comment

by:mattgoolsby
Comment Utility
I have found a temporary workaround.  I am putting the ProgramNumber values into an array.  Instead of a "Do" loop, I use a "For" loop to loop through each value of the array, build my second SQL statement, and any other processing I need done.  This is working fine.

However, I would still like to know the source of my initial problem so I can avoid it in the future.
0
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 125 total points
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now