?
Solved

Transaction context in use by another session.  Error

Posted on 2003-11-20
10
Medium Priority
?
1,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 22

Expert Comment

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

Author Comment

by:mattgoolsby
ID: 9787918
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
ID: 9788474
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:mattgoolsby
ID: 9788545
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
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9788550
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
ID: 9788590
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
ID: 9788615
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 500 total points
ID: 9788677
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

765 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