COM runs in VB client, fails in ASP 
Author Message
 COM runs in VB client, fails in ASP

I've been having problems running my COM component.
Although it runs successfully in VB, there's a problem when running it in
aSP.

The component's job is to get records from a Sybase database.
The component passes a disconnected recordsource to the client.

I just want to know if I missed something in the creation of the DLL.
I set it as global multiuse.
I also wanted to know why it runs fine in VB Client, but it fails in ASP.
I am using VB6.0 and PWS.

----------------Here's the code for the VB Client:--------------------------

Dim vProc As clsProcMTS
Dim vProc2 As clsProcMTS
Dim Rs As New ADODB.Recordset
Dim Rs2 As New ADODB.Recordset
Dim value1 As String
Dim value2 As String

Set vProc = New clsProcMTS
vProc.ProcName = "PROC1"
vProc.AddParam (value1)
vProc.AddParam (value2)
Set Rs = vProc.GetRecords()
Do While Not Rs.EOF
    Debug.Print Rs.Fields(0).Value
    Rs.MoveNext
Loop
Rs.Close

Set vProc2 = New clsProcMTS
vProc2.ProcName = "PROC2"
Set Rs = vProc2.GetRecords()
Set vProc2 = Nothing
Do While Not Rs.EOF
    Debug.Print Rs.Fields(0).Value
    Rs.MoveNext
Loop
Rs.Close
MsgBox ("Finished")

--------------Here's the code for ASP:------------------


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Dim vProc
Dim vProc2
Dim Rs
Dim Rs2

Set vProc = Server.CreateObject("comSybase.clsProcMTS")
vProc.ProcName = "PROC1"
vProc.AddParam (value1)
vProc.AddParam (value2)
Set Rs = vProc.GetRecords()
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing

Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
vProc2.ProcName = "PROC2"
Set Rs2 = vProc2.GetRecords()
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs2.Close
Set Rs2 = Nothing
%>
<P>&nbsp;</P>

</BODY>
</HTML>



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Exactly what line does it fail on?

Jonathan Allen


Quote:

> I've been having problems running my COM component.
> Although it runs successfully in VB, there's a problem when running it in
> aSP.

> The component's job is to get records from a Sybase database.
> The component passes a disconnected recordsource to the client.

> I just want to know if I missed something in the creation of the DLL.
> I set it as global multiuse.
> I also wanted to know why it runs fine in VB Client, but it fails in ASP.
> I am using VB6.0 and PWS.

> ----------------Here's the code for the VB

Client:--------------------------
Quote:

> Dim vProc As clsProcMTS
> Dim vProc2 As clsProcMTS
> Dim Rs As New ADODB.Recordset
> Dim Rs2 As New ADODB.Recordset
> Dim value1 As String
> Dim value2 As String

> Set vProc = New clsProcMTS
> vProc.ProcName = "PROC1"
> vProc.AddParam (value1)
> vProc.AddParam (value2)
> Set Rs = vProc.GetRecords()
> Do While Not Rs.EOF
>     Debug.Print Rs.Fields(0).Value
>     Rs.MoveNext
> Loop
> Rs.Close

> Set vProc2 = New clsProcMTS
> vProc2.ProcName = "PROC2"
> Set Rs = vProc2.GetRecords()
> Set vProc2 = Nothing
> Do While Not Rs.EOF
>     Debug.Print Rs.Fields(0).Value
>     Rs.MoveNext
> Loop
> Rs.Close
> MsgBox ("Finished")

> --------------Here's the code for ASP:------------------


> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> </HEAD>
> <BODY>
> <%
> Dim vProc
> Dim vProc2
> Dim Rs
> Dim Rs2

> Set vProc = Server.CreateObject("comSybase.clsProcMTS")
> vProc.ProcName = "PROC1"
> vProc.AddParam (value1)
> vProc.AddParam (value2)
> Set Rs = vProc.GetRecords()
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs.Close
> Set Rs = Nothing

> Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
> vProc2.ProcName = "PROC2"
> Set Rs2 = vProc2.GetRecords()
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs2.Close
> Set Rs2 = Nothing
> %>
> <P>&nbsp;</P>

> </BODY>
> </HTML>



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP

Ricky:

Are you sure you don't have a security problem? ie the security context of
your IIS thread (IUSR_computerName/IUSR_computerName) may not have RX
permissions  to instantiate the COM dll.

Marc


Quote:
> Exactly what line does it fail on?

> Jonathan Allen



> > I've been having problems running my COM component.
> > Although it runs successfully in VB, there's a problem when running it
in
> > aSP.

> > The component's job is to get records from a Sybase database.
> > The component passes a disconnected recordsource to the client.

> > I just want to know if I missed something in the creation of the DLL.
> > I set it as global multiuse.
> > I also wanted to know why it runs fine in VB Client, but it fails in
ASP.
> > I am using VB6.0 and PWS.

> > ----------------Here's the code for the VB
> Client:--------------------------

> > Dim vProc As clsProcMTS
> > Dim vProc2 As clsProcMTS
> > Dim Rs As New ADODB.Recordset
> > Dim Rs2 As New ADODB.Recordset
> > Dim value1 As String
> > Dim value2 As String

> > Set vProc = New clsProcMTS
> > vProc.ProcName = "PROC1"
> > vProc.AddParam (value1)
> > vProc.AddParam (value2)
> > Set Rs = vProc.GetRecords()
> > Do While Not Rs.EOF
> >     Debug.Print Rs.Fields(0).Value
> >     Rs.MoveNext
> > Loop
> > Rs.Close

> > Set vProc2 = New clsProcMTS
> > vProc2.ProcName = "PROC2"
> > Set Rs = vProc2.GetRecords()
> > Set vProc2 = Nothing
> > Do While Not Rs.EOF
> >     Debug.Print Rs.Fields(0).Value
> >     Rs.MoveNext
> > Loop
> > Rs.Close
> > MsgBox ("Finished")

> > --------------Here's the code for ASP:------------------


> > <HTML>
> > <HEAD>
> > <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> > </HEAD>
> > <BODY>
> > <%
> > Dim vProc
> > Dim vProc2
> > Dim Rs
> > Dim Rs2

> > Set vProc = Server.CreateObject("comSybase.clsProcMTS")
> > vProc.ProcName = "PROC1"
> > vProc.AddParam (value1)
> > vProc.AddParam (value2)
> > Set Rs = vProc.GetRecords()
> > Do While Not Rs.EOF
> >     Response.Write(Rs.Fields(0).Value)
> >     Rs.MoveNext
> > Loop
> > Rs.Close
> > Set Rs = Nothing

> > Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
> > vProc2.ProcName = "PROC2"
> > Set Rs2 = vProc2.GetRecords()
> > Do While Not Rs.EOF
> >     Response.Write(Rs.Fields(0).Value)
> >     Rs.MoveNext
> > Loop
> > Rs2.Close
> > Set Rs2 = Nothing
> > %>
> > <P>&nbsp;</P>

> > </BODY>
> > </HTML>



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
The ASP code fails here


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Dim vProc
Dim vProc2
Dim Rs
Dim Rs2

Set vProc = Server.CreateObject("comSybase.clsProcMTS")
vProc.ProcName = "PROC1"
vProc.AddParam (value1)
vProc.AddParam (value2)
Set Rs = vProc.GetRecords()
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing

Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")  --------> Error is
pointing here in ASP
vProc2.ProcName = "PROC2"
Set Rs2 = vProc2.GetRecords()
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs2.Close
Set Rs2 = Nothing
%>
<P>&nbsp;</P>

</BODY>
</HTML>

Here's the ugly code for the COM dll
See arrow for failure...

Public Function GetRecords() As ADODB.Recordset
    Dim col As Variant
    Dim lcount As Integer
    Dim Conn As ADODB.Connection
    Dim ADOComm As New ADODB.Command
    Dim ADORs As New ADODB.Recordset
    Dim objCtx As ObjectContext

    'use GetObjectContext from MTS
    Set objCtx = GetObjectContext

    'create an instance of the ADO object Connection in the MTS environment
    Set Conn = objCtx.CreateInstance("ADODB.Connection")

    'open connection
    Conn.Open "DSN=testdata", "username", "password"  ------------->might be
failing here

remember everything works fine in VB

compiled or in debug mode
    'use client side cursors
    Conn.CursorLocation = adUseClient

    lcount = 1
    Set ADOComm.ActiveConnection = Conn
    ADOComm.CommandText = m_pname
    ADOComm.CommandType = adCmdStoredProc
    For Each col In m_col
        ADOComm.Parameters(lcount).Value = m_col.Item(lcount)
        lcount = lcount + 1
    Next
    ADORs.CursorLocation = adUseClient
    ADORs.Open ADOComm

    'Disconnect recordset from the connection
    ADORs.ActiveConnection = Nothing

    'Assign recordset to function name
    Set GetRecords = ADORs.Clone

    ADORs.Close
    Conn.Close
    Set ADORs = Nothing
    Set Conn = Nothing

    'indicate to MTS that the object's work completed successfully
    'and that it can deactivate the object and thus free resources
    objCtx.SetComplete
End Function



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Marc,

I guess not because the error actually happens on the second instantiation.

The first call to GetRecords() runs fine.  The second GetRecords() call
fails.

Thanks.

Ricky



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP

Correction.......error location see arrow

The ASP code fails here


<HTML
<HEAD
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"
</HEAD
<BODY
<%
Dim vProc
Dim vProc2
Dim Rs
Dim Rs2

Set vProc = Server.CreateObject("comSybase.clsProcMTS")
vProc.ProcName = "PROC1"
vProc.AddParam (value1)
vProc.AddParam (value2)
Set Rs = vProc.GetRecords()
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing

Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
vProc2.ProcName = "PROC2"
Set Rs2 = vProc2.GetRecords()  -------->>> Error is pointing here in ASP
Do While Not Rs.EOF
    Response.Write(Rs.Fields(0).Value)
    Rs.MoveNext
Loop
Rs2.Close
Set Rs2 = Nothing
%
<P&nbsp;</P

</BODY
</HTML

Here's the ugly code for the COM dll
See arrow for failure...

Public Function GetRecords() As ADODB.Recordset
    Dim col As Variant
    Dim lcount As Integer
    Dim Conn As ADODB.Connection
    Dim ADOComm As New ADODB.Command
    Dim ADORs As New ADODB.Recordset
    Dim objCtx As ObjectContext

    'use GetObjectContext from MTS
    Set objCtx = GetObjectContext

    'create an instance of the ADO object Connection in the MTS environment
    Set Conn = objCtx.CreateInstance("ADODB.Connection")

    'open connection
    Conn.Open "DSN=testdata", "username", "password"  -------------might be
failing here

remember everything works fine in VB

compiled or in debug mode
    'use client side cursors
    Conn.CursorLocation = adUseClient

    lcount = 1
    Set ADOComm.ActiveConnection = Conn
    ADOComm.CommandText = m_pname
    ADOComm.CommandType = adCmdStoredProc
    For Each col In m_col
        ADOComm.Parameters(lcount).Value = m_col.Item(lcount)
        lcount = lcount + 1
    Next
    ADORs.CursorLocation = adUseClient
    ADORs.Open ADOComm

    'Disconnect recordset from the connection
    ADORs.ActiveConnection = Nothing

    'Assign recordset to function name
    Set GetRecords = ADORs.Clone

    ADORs.Close
    Conn.Close
    Set ADORs = Nothing
    Set Conn = Nothing

    'indicate to MTS that the object's work completed successfully
    'and that it can deactivate the object and thus free resources
    objCtx.SetComplete
End Function



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
I'm wanting to say that your opening the database in exclusive mode, since
that would allow you to open it once but not a second time. However, that
doesn't seem to be occurring.

Can you use vProc twice?

Jonathan Allen


Quote:

> Correction.......error location see arrow

> The ASP code fails here


> <HTML
> <HEAD
> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"
> </HEAD
> <BODY
> <%
> Dim vProc
> Dim vProc2
> Dim Rs
> Dim Rs2

> Set vProc = Server.CreateObject("comSybase.clsProcMTS")
> vProc.ProcName = "PROC1"
> vProc.AddParam (value1)
> vProc.AddParam (value2)
> Set Rs = vProc.GetRecords()
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs.Close
> Set Rs = Nothing

> Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
> vProc2.ProcName = "PROC2"
> Set Rs2 = vProc2.GetRecords()  -------->>> Error is pointing here in ASP
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs2.Close
> Set Rs2 = Nothing
> %
> <P&nbsp;</P

> </BODY
> </HTML

> Here's the ugly code for the COM dll
> See arrow for failure...

> Public Function GetRecords() As ADODB.Recordset
>     Dim col As Variant
>     Dim lcount As Integer
>     Dim Conn As ADODB.Connection
>     Dim ADOComm As New ADODB.Command
>     Dim ADORs As New ADODB.Recordset
>     Dim objCtx As ObjectContext

>     'use GetObjectContext from MTS
>     Set objCtx = GetObjectContext

>     'create an instance of the ADO object Connection in the MTS
environment
>     Set Conn = objCtx.CreateInstance("ADODB.Connection")

>     'open connection
>     Conn.Open "DSN=testdata", "username", "password"  -------------might
be
> failing here

> remember everything works fine in VB

> compiled or in debug mode
>     'use client side cursors
>     Conn.CursorLocation = adUseClient

>     lcount = 1
>     Set ADOComm.ActiveConnection = Conn
>     ADOComm.CommandText = m_pname
>     ADOComm.CommandType = adCmdStoredProc
>     For Each col In m_col
>         ADOComm.Parameters(lcount).Value = m_col.Item(lcount)
>         lcount = lcount + 1
>     Next
>     ADORs.CursorLocation = adUseClient
>     ADORs.Open ADOComm

>     'Disconnect recordset from the connection
>     ADORs.ActiveConnection = Nothing

>     'Assign recordset to function name
>     Set GetRecords = ADORs.Clone

>     ADORs.Close
>     Conn.Close
>     Set ADORs = Nothing
>     Set Conn = Nothing

>     'indicate to MTS that the object's work completed successfully
>     'and that it can deactivate the object and thus free resources
>     objCtx.SetComplete
> End Function



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Ricky:

Sorry, I didn;t read your code properly in my 1st response- however, I think
that you're not adhering to the "stateless" paradigm required for your MTS
object

eg in ASP, you instantiate the object and then invoke 4 methods
consecutively:
    Set vProc = Server.CreateObject("comSybase.clsProcMTS")
    vProc.ProcName = "PROC1"
    vProc.AddParam (value1)
    vProc.AddParam (value2)
    Set Rs = vProc.GetRecords()

I asssume that the result from GetRecords() is dependent on the 3 previous
calls?

If so, then this approach can return unexpected behaviour, which may be the
root cause of the problem:

Your server component also references a class member var  m_pname in the
follwoing line::
    ADOComm.CommandText = m_pname

Again, I assume that the value of this variable is supposed to be set by
method/property call prior to invoking GetRecords()?

You shouldn;t make assumptions about your state in MTS as you never know
what the life span of the object may be, but rather pass the server
everything that it needs as arguments in one single call:
eg:     Set Rs = vProc.GetRecords("PROC1",value1, value2)

If not, this will cause the line:
ADORs.Open ADOComm to fail at sooner or later.

Marc.


Quote:
> Marc,

> I guess not because the error actually happens on the second
instantiation.

> The first call to GetRecords() runs fine.  The second GetRecords() call
> fails.

> Thanks.

> Ricky



Tue, 14 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Ricky,     If this is on an NT box,  check the server and be absolutely sure
that the frontpage server extensions are installed and ok,  as well as the
IIS files required for ASP and COM.  If one file is missing or messed up,
you will never get it working..

--
Sincerely,

Todd B - CEO - Agendum Software


Quote:
> I've been having problems running my COM component.
> Although it runs successfully in VB, there's a problem when running it in
> aSP.

> The component's job is to get records from a Sybase database.
> The component passes a disconnected recordsource to the client.

> I just want to know if I missed something in the creation of the DLL.
> I set it as global multiuse.
> I also wanted to know why it runs fine in VB Client, but it fails in ASP.
> I am using VB6.0 and PWS.

> ----------------Here's the code for the VB

Client:--------------------------
Quote:

> Dim vProc As clsProcMTS
> Dim vProc2 As clsProcMTS
> Dim Rs As New ADODB.Recordset
> Dim Rs2 As New ADODB.Recordset
> Dim value1 As String
> Dim value2 As String

> Set vProc = New clsProcMTS
> vProc.ProcName = "PROC1"
> vProc.AddParam (value1)
> vProc.AddParam (value2)
> Set Rs = vProc.GetRecords()
> Do While Not Rs.EOF
>     Debug.Print Rs.Fields(0).Value
>     Rs.MoveNext
> Loop
> Rs.Close

> Set vProc2 = New clsProcMTS
> vProc2.ProcName = "PROC2"
> Set Rs = vProc2.GetRecords()
> Set vProc2 = Nothing
> Do While Not Rs.EOF
>     Debug.Print Rs.Fields(0).Value
>     Rs.MoveNext
> Loop
> Rs.Close
> MsgBox ("Finished")

> --------------Here's the code for ASP:------------------


> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> </HEAD>
> <BODY>
> <%
> Dim vProc
> Dim vProc2
> Dim Rs
> Dim Rs2

> Set vProc = Server.CreateObject("comSybase.clsProcMTS")
> vProc.ProcName = "PROC1"
> vProc.AddParam (value1)
> vProc.AddParam (value2)
> Set Rs = vProc.GetRecords()
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs.Close
> Set Rs = Nothing

> Set vProc2 = Server.CreateObject("comSybase.clsProcMTS")
> vProc2.ProcName = "PROC2"
> Set Rs2 = vProc2.GetRecords()
> Do While Not Rs.EOF
>     Response.Write(Rs.Fields(0).Value)
>     Rs.MoveNext
> Loop
> Rs2.Close
> Set Rs2 = Nothing
> %>
> <P>&nbsp;</P>

> </BODY>
> </HTML>



Thu, 16 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Thank you for your response.  I really appreciate it.

Quote:
>Can you use vProc twice?

No,  the same thing happens.


Fri, 17 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Marc,

Thanks for your help.  Your explanation was very clear, concise, and
straightforward.   I will apply your suggestion.  I wonder if you could
recommend good books for me with regard to the topic.

Quote:
>I asssume that the result from GetRecords() is dependent on the 3 previous
>calls?

Yes, it is dependent on the previous calls.

Thanks again for everyone's help!  I'll probably need your help again guys!



Fri, 17 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Thank you for your response.

Actually I have another web app running in this server.
Everything is working fine.  Now, I have this copy of the same app, but I
wanted it to connect to the database using a COM dll instead of ASP scripts.
I read somewhere that it's better to use a COM dll for that so that you
don't have to change
your connections scripts everytime there is a considerable change.

It's an old app and it seems the design was not that good.

Thanks again for your thought!



Fri, 17 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Jonathan,

You may have a point because the error seems to happen
when I try to connect the second time.
I don't know if I'm opening the database in exclusive mode.
Can you tell me how I could check if I'm doing that?

Thanks!

Ricky



Fri, 17 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Ricky:

I found "Designing Component Based Applications" by Mary Kirtland, Microsoft
Press to be a good starting point on MTS.
This book apparently has a 5 star rating on amazon.com

She illustrates her examples both in VB & C++.

Regards,

Marc


Quote:
> Marc,

> Thanks for your help.  Your explanation was very clear, concise, and
> straightforward.   I will apply your suggestion.  I wonder if you could
> recommend good books for me with regard to the topic.

> >I asssume that the result from GetRecords() is dependent on the 3
previous
> >calls?

> Yes, it is dependent on the previous calls.

> Thanks again for everyone's help!  I'll probably need your help again
guys!



Fri, 17 Jan 2003 03:00:00 GMT  
 COM runs in VB client, fails in ASP
Not without knowing what database engine your using. Check your DSN entry.

Jonathan Allen


Quote:
> Jonathan,

> You may have a point because the error seems to happen
> when I try to connect the second time.
> I don't know if I'm opening the database in exclusive mode.
> Can you tell me how I could check if I'm doing that?

> Thanks!

> Ricky



Fri, 17 Jan 2003 03:00:00 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. ASP to COM to DCOM call fails

2. Compiled COM fails in ASP

3. ASP/COM programming: a failed model?

4. fat client (MSMQ, VB Program) or thin client (ASP page then have Web server use MSMQ)

5. Application fails to run on client

6. com object will not read registry when com object called from asp (vb works fine)

7. Running ASP on a client

8. Running ASP on a client

9. ASP not running COM objects from within VBScript

10. ASP and COM Ran out of memory Error

11. COM objects on ASP communicating with running prog

12. ASP Export to PDF Failing....(Hair failing out)

 

 
Powered by phpBB® Forum Software