Wierd error while trying to instantiate an MTS object

Hi,

I am getting an error

"13704, Operation is not allowed when the object is closed"

when I am trying to create an instance of a component configured to run
under MTS. Everything runs fine if I try it from VB.

I am having Win2000 Professional, IIS 5.0, SQL Server 7.0 and Component
Services all on one machine.

Here is the code for the COM component

BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 4  'RequiresNewTransaction
END
Attribute VB_Name = "clsTitles"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Implements ObjectControl

Private objContext  As ObjectContext

Private Const MSG_FAILED = "FAILED"
Private Const MSG_SUCCESS = "SUCCESS"

Private Sub ObjectControl_Activate()
    Set objContext = GetObjectContext()
End Sub
Private Sub ObjectControl_Deactivate()
    Set objContext = Nothing
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
    ObjectControl_CanBePooled = True
End Function

Public Function AddTitle(ByVal strConnection As String, ByVal rsTitles As
ADODB.Recordset) As String
    On Error GoTo ErrorHandler

    Dim cnPubs      As ADODB.Connection
    Dim adError     As ADODB.Error
    Dim strErrorMsg As String

    AddTitle = MSG_FAILED

    Set cnPubs = New ADODB.Connection
    cnPubs.Open strConnection

    Set rsTitles.ActiveConnection = cnPubs
    rsTitles.UpdateBatch

    AddTitle = MSG_SUCCESS

    objContext.SetComplete

ExitFunction:
    rsTitles.Close
    cnPubs.Close

    Set adError = Nothing
    Set rsTitles = Nothing
    Set cnPubs = Nothing

    Exit Function
ErrorHandler:
    objContext.SetAbort

    If cnPubs.Errors.Count > 0 Then
        For Each adError In cnPubs.Errors
            strErrorMsg = strErrorMsg & " = " & adError.NativeError & " - "
& adError.Description
        Next adError
    End If
    AddTitle = MSG_FAILED & strErrorMsg

    GoTo ExitFunction
End Function

-------------------

And this is how I am calling from an ASP page

Set oTitles = Server.CreateObject("CTitles.clsTitles")
 Response.Write(Err.Number & " = " & Err.Description)
 strMsg = oTitles.AddTitle(strConn, rsTitles)



Please help

Thanks,
Rahul


LVL 4
agarwal_rahulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PiNCommented:
Looks like the connection is not opened.
In that case you jump in your error handler ErrorHandler and that continues with Exit_Function.
Then you try to close the RS and Connection and that might cause your error, because they are closed.

You could try to check the RS- and Connections State Property before closing them

if (rsTitles.State = adOpen) Then rsTitles.Close
if (cnPubs.State = adOpen) Then cnPubs.Close

Otherwise you could move the errorhandler ErrorHandler down to when you know that both (RS and COnn) are open and add another Errorhandler that handles the OpenFailed-Errors beforehand.

Hope that helps,

PiN
0
agarwal_rahulAuthor Commented:
As I said it is working fine when I try to use it from VB.

Secondly, I can connect to the database and open the connection, the problem is when I am trying to instantiate the object.

Thanks for help

rahul
0
mgfranzCommented:
Your problem is with the As keyword.  VBScript only supports the variant data type, the As keyword is not supported, and you don't have to worry about the data type returned by your custom function.  All functions defined by the Function statement return data of type variant.

Mark
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

agarwal_rahulAuthor Commented:
mgfranz:

That code is from the VB Component implemented as a DLL not VBScript.

Thanks
Rahul
0
PepsterCommented:
After going to the VBUG conferece yesterday I can`t remember why but if you use a VB dll and MTS then you have to set Persistable to true.

Hope this helps
0
a201348Commented:
Here is my penny:

Put the SetComplete after the
rsTitles.Close
cnPubs.Close

It works in VB because there is no real transaction context when you run it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed.  Also a question is posted there specific to these changes that apply to the experts here.  Also, I am including the link to our All Topics, since many new ones have recently been added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.