Solved

Transaction context in use by another session.  Error

Posted on 2003-11-20
10
1,759 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 125 total points
ID: 9788677
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

749 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