Link to home
Start Free TrialLog in
Avatar of leo_wh_cheung
leo_wh_cheung

asked on

Urgent: Cannot create new connection because in manual or distributed transaction mode.

Urgent: 100 more Points will be added if the problems can be solved.

Error occur when execute the following ASP program:

Cannot create new connection because in manual or distributed transaction mode.


Set cn1 = Server.CreateObject("ADODB.Connection")
    cn1.open ....
cn1.BeginTrans
for i= 1 to x


empDesc=FindIdDescrption(ID,cn1)
response.write empDesc


cn1.execute "insert table1...."
cn1.execute "update table3"

next
cn1.CommitTrans

Function FindIdDescription(tmpCode,tmpcn1)
  Dim rstemp

    set rstemp = server.CreateObject("adodb.recordset")
    sqlstm ="select * from table2 "
    rstemp.open sqlstm ,tmpcn1
    If not rstemp.eof then
       FindDescription = rstemp("Desc")
    Else
       FindDescription = "N"
    End If
    rstemp.close
    set rstemp=nothing

End Function

How to solve this problem?
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Urgent:  Please maintain your open questions:
Query cannot be updated Date: 11/29/2000 01:35AM PST  
https://www.experts-exchange.com/questions/12010641/Query-cannot-be-updated.html
ASP command change to  Java Command Date: 06/06/2001 03:09AM PST  
https://www.experts-exchange.com/questions/20130580/ASP-command-change-to-Java-Command.html
Zip a file in Active Server Pages Date: 01/30/2001 02:01AM PST
https://www.experts-exchange.com/questions/20065389/Zip-a-file-in-Active-Server-Pages.html
How can I set the page never timeout expired? Date: 11/30/2000 08:06PM PST  
https://www.experts-exchange.com/questions/12037560/How-can-I-set-the-page-never-timeout-expired.html

Thanks,
Anthony

I have a feeling that you oversimplified your ASP code here.  There is a known issue with this type of code, but only if there is an open rs with pending actions when you try to open another rs.

This error only occurs if you use the default Firehose cursor.  You can prevent it by setting something other than a read-only, forward-only cursor on the rsTemp open.
Take a look at this article from MSDN:
PRB: SQLOLEDB Allows Only One Connection in Scope of Transaction
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q272358&

Thank you for maintaining your open questions,
Anthony
ASKER CERTIFIED SOLUTION
Avatar of CFXPERT
CFXPERT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leo_wh_cheung
leo_wh_cheung

ASKER

CFXPERT,

I solve this problem by the following method:

1. Define(Dim) a local variable in the function. Otherwise, other function can use this variable and error may occur.

2. Create another connection to update the recordset

3. make sure you close it and set it to nothing before trying to open a new connection.

Thanks!

Leo
Not a problem.  Glad you got it fixed.

:)
KWK