[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Transaction context in use by another session.  Error

Posted on 2003-11-20
10
Medium Priority
?
1,769 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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, show how to shrink a transaction log file down to a reasonable size.

649 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