vb dot net com+ Component rerun

S

Stuart Dee

Hi,

I have created a com+ component with vb dot net
using jit activation and transactions

If i call it like this

x=createobject("mycomp")
x.dispose

it works fine

if i try it in a loop it then locks up.
i would like to run it this way. What do i need to do


x=createobject("mycomp")

do while not eof
x.execute

LOOP

tia

Stu
 
H

Herfried K. Wagner [MVP]

* "Stuart Dee said:
I have created a com+ component with vb dot net
using jit activation and transactions

If i call it like this

x=createobject("mycomp")
x.dispose

it works fine

if i try it in a loop it then locks up.
i would like to run it this way. What do i need to do


x=createobject("mycomp")

do while not eof
x.execute

LOOP

That should work. Maybe there is a bug in the implementation of 'Execute'?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
G

Guest

Hi,

I dont thinkso as it works fine if i call it like this

do while not eof
x=createobject("mycomp")
x.execute
set x=null
LOOP
 
P

Peter Huang

Hi Stuart,

Can you modify your code as simple as possible and post in the newsgroup
for me to reproduce the problem?
do while not eof
x=createobject("mycomp")
x.execute
set x=null
LOOP

Do you call the component in the Vb6 or VB.NET?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
S

Stuart Dee

Currently the component is called from
vb script,dot net and will be also in access

Im more interested in wether it should work
my assembly uses strong names like the following and ive
included some code from the main program. Hopefully you
may spot something

Regards

Stu



Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Imports System.EnterpriseServices

Imports System.Data
Imports System.Data.SqlClient
Imports CGCalc.Common
Imports CGCalc.CalcDataAccess

Namespace cgCalc
<Transaction(TransactionOption.Required)> _
Public Class CalcEngine
Inherits ServicedComponent

Private Shared s_count As Integer = 0
Private m_count As Integer
Private m_canBePooled As Boolean = True

Public Sub New()
MyBase.New()
m_count =
System.Threading.Interlocked.Increment(s_count)
End Sub

Protected Overrides Function canBePooled() As
Boolean
Return m_canBePooled
End Function

Protected Overrides Sub activate()
m_canBePooled = False
End Sub
Protected Overrides Sub deactivate()
m_canBePooled = True
End Sub

Public Sub reset()
End Sub
Public ReadOnly Property version() As String
Get
version = CgCalcConfiguration.CGTVersion
End Get
End Property
Public Property Calcmode() As Integer
Get
Calcmode = m_CalcMode
End Get

Set(ByVal Value As Integer)
If Value < 0 Or Value > 3 Then
Throw New Exception("Invalid Calc
mode: " & CStr(Value))
End If
m_CalcMode = Value
CgCalcConfiguration.glo.gCalcMode = Value

End Set

End Property

Public Property Client() As Integer
Get
Client = CInt(m_Client)
End Get
Set(ByVal Value As Integer)

If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If

objCalcDB.getClientType(m_CalcMode, _
Value)

m_Client = Value

End Set
End Property

Public Property asset(ByVal passet As Integer) As
Integer
Get
passet = CInt(m_Asset)
End Get

Set(ByVal Value As Integer)
Dim reccount As Long

If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If

'check asset exists
reccount = objCalcDB.AssetExistsCheck
(Value)

If reccount = 0 Then
Throw New Exception("Invalid Asset
Code: " & passet)
End If

m_Asset = Value

End Set
End Property
Public ReadOnly Property ErrorText() As String
Get
ErrorText = m_Error
End Get
End Property
Public ReadOnly Property MultPoss() As Boolean
Get
MultPoss = m_Multpos
End Get
End Property
Public Property MQuantity(ByVal Qty As Double) As
Double
Get
Dim TaxYear As Integer, LoadTable As
Boolean
Dim tcg() As CalcInfo

If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If

Call Check_Parms()

LoadTable = True

Call objModel.AcheiveRequiredTGainLoss
(m_Client, tcg, m_Asset, MDate, Price, _
m_Gain, m_ReturnGainLoss, GraphReqd, _
m_Qty, m_Multpos, m_ReturnCode,
AuditReqd, m_Error, LoadTable, TaxYear, m_CalcMode, 0)


MQuantity = m_Qty

If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If

End Get
Set(ByVal Value As Double)
m_Qty = CDec(Value)
End Set
End Property
Public Property MGain() As Decimal
Get

Dim TaxYear As Integer
Dim tcg() As CalcInfo
Dim LoadTable As Boolean, UpdateData As
Boolean, IncludeUnconfirmed As Boolean

If Not
CgCalcConfiguration.glo.gGlobalsLoaded Then
Throw New Exception("CGcalc has not
been initialised")
End If


Call Check_Parms()

LoadTable = True
UpdateData = True
IncludeUnconfirmed = False

Call objModel.ComputeGainLoss(m_Client,
tcg, m_Asset, Price, MDate, _
TaxYear, m_Qty, m_NetGL, m_LossApplied,
m_Taper, m_Gain, _
m_LossCF, m_Error, UpdateData,
LoadTable, IncludeUnconfirmed, _
AuditReqd, m_ReturnCode, m_CalcMode)

MGain = m_Gain

If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If

End Get
Set(ByVal Value As Decimal)
m_Gain = Value
End Set
End Property

Public ReadOnly Property ReturnGain() As Decimal
Get
ReturnGain = m_ReturnGainLoss
End Get
End Property

Private Sub Check_Parms()
Dim holdingsDR As SqlDataReader
Dim reccount As Long
Dim validated_asset() As Boolean
Dim MaxHldgs As Integer, AssetX As Integer,
maxtxns As Integer, X As Integer
Dim NullTxn As CGcalcTxnStructure

If m_Client = 0 Then
m_ReturnCode = 9
Throw New Exception("Client not
specified.")
End If

If m_CalcMode < 0 Or m_CalcMode > 3 Then
m_ReturnCode = 9
Throw New Exception("Calcmode incorrectly
specified: " & m_CalcMode)
End If

If m_CalcMode =
CgCalcConfiguration.WHAT_IF_CALC_MODE Then
If m_Asset = 0 Then
m_ReturnCode = 9
Throw New Exception("Asset not
specified.")
End If

'check client has a holding in the asset
to model
reccount = objCalcDB.clientAssetHldgExists
(m_Client, m_Asset)

If reccount = 0 Then
m_ReturnCode = 9
Throw New Exception("Client does not
have a holding in the asset.")
End If
End If

If m_CalcMode =
CgCalcConfiguration.WHAT_IF_CALC_MODE Then
'check date is >= current
If MDate < System.DateTime.Now Then
m_ReturnCode = 9
Throw New Exception("Modelling date
cannot be in the past.")
End If
End If

If m_CalcMode =
CgCalcConfiguration.MODEL_SLE_TXNS_MODE Or m_CalcMode =
CgCalcConfiguration.MODEL_PUR_TXNS_MODE Then

maxtxns = UBound(m_ModelTxns)

For X = 1 To maxtxns
If CInt(m_ModelTxns(X).InQty) = 0 Then
Exit For
End If
MaxHldgs = X
Next X

If MaxHldgs > 0 Then

ReDim validated_asset(MaxHldgs)

'validate all the holdings exist
holdingsDR =
objCalcDB.ClientHoldingList(m_Client)

Do While holdingsDR.Read
For AssetX = 1 To MaxHldgs
If CLng(holdingsDR.Item
("AssetID")) = m_ModelTxns(AssetX).AssetID Then
validated_asset(AssetX) =
True
End If
Next AssetX

Loop
End If

For AssetX = 1 To MaxHldgs

If Not validated_asset(AssetX) Then
m_ReturnCode = 9
Throw New Exception("Client does
not have a holding in the asset." & m_ModelTxns
(AssetX).AssetID)
End If
Next AssetX
End If


End Sub
<AutoComplete()> _
Public Function CalcCGT() As Integer

Dim reccount As Long
Dim tcg() As CalcInfo

m_ReturnCode = 0

If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
Throw New Exception("CGcalc has not been
initialised")
End If


Call Check_Parms()

objEvent.EventProcessor(m_Client, tcg,
m_CalcMode, m_Asset, 0, Price, _
True, True, False,
AuditReqd, m_ReturnCode)

CalcCGT = m_ReturnCode


If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
m_ReturnCode = 8
CalcCGT = 8
'Err.Raise 111 + gObjectError, ,
gFailedUpdateText
End If

Return CalcCGT
End Function
Public ReadOnly Property ReturnCode() As String
Get
ReturnCode = CStr(m_ReturnCode)
End Get
End Property

Public Sub InitialiseClass(ByVal PServer As
String, _
ByVal PDatabase As String, _
Optional ByVal PUser As String = "", _
Optional ByVal PPassword As String = "")
If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
ReDim CgCalcConfiguration.glo.gEELtxt(9)

Call load_globals(PServer, _
PDatabase, _
PUser, _
PPassword, _
m_Error)

End If

If m_Error <> "" Then
Throw New Exception(m_Error)
End If


End Sub


Public Function Execute(ByVal Action As String) As
String

'A generic function for future
methods/properties without
'inflicting painful version incompatability
issues.
'For use refer francesco balena's book
prog'ing vb6 pg850

Select Case Action

Case "CGCALC"

Execute = "test generic function"

Case "AutoGenerateAllDisposals"
'this function just sets the boolean
value to state that all
'modelled txns will be generated
automatically from the notionals.
'Ordinarily this would be a class
variable, but rolling out a new class is
'too painful...!
m_AutoGenerateAllDisposals = True
Execute = "Set
AutoGenerateAllDisposals to true."

End Select

Return Execute
End Function

Public Property ModelTxns() As CGcalcTxnType()
Get
ModelTxns = m_ModelTxns
End Get
Set(ByVal Value As CGcalcTxnType())
m_ModelTxns = Value
End Set
End Property

<AutoComplete()> _
Function ModelTxnSet() As Integer

Dim TaxYear As Integer
Dim tcg() As CalcInfo

If Not CgCalcConfiguration.glo.gGlobalsLoaded
Then
Throw New Exception("CGcalc has not been
initialised")
End If


Call Check_Parms()

Select Case m_CalcMode

Case
CgCalcConfiguration.MODEL_SLE_TXNS_MODE

Call objModel.ModelMultipleDisposals
(m_Client, tcg, m_ModelTxns, ModelTxnSortID, m_NetGL, _
m_LossApplied, m_Taper,
m_ReturnGainLoss, m_LossCF, m_Error, m_ReturnCode,
m_CalcMode, _
m_AutoGenerateAllDisposals)

Case
CgCalcConfiguration.MODEL_PUR_TXNS_MODE

Call objModel.ModelMultipleAcquisitions
(m_Client, tcg, m_ModelTxns, m_NetGL, _
m_LossApplied, m_Taper,
m_ReturnGainLoss, m_LossCF, m_Error, m_ReturnCode,
m_CalcMode)

End Select

ModelTxnSet = m_ReturnCode

MGain = m_Gain

If InStr(CgCalcConfiguration.glo.gErrText,
CgCalcConfiguration.gFAILEDUPDATETEXT) <> 0 Then
Throw New Exception
(CgCalcConfiguration.gFAILEDUPDATETEXT)
End If

Return ModelTxnSet
End Function


End Class
End Namespace
<Assembly: ApplicationActivation(ActivationOption.Server)>
<Assembly: AssemblyTitle("Calcxxxxx")>
<Assembly: ApplicationName("xxxxxx(Dot Net)")>
<Assembly: AssemblyDescription("Calculator Engine")>
<Assembly: AssemblyCompany("xxxxxx Financial Systems")>
<Assembly: AssemblyProduct("xxxx")>
<Assembly: AssemblyCopyright("2003")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
<Assembly: AssemblyKeyFile("DotNetCalc.snk")>

'The following GUID is for the ID of the typelib if this
project is exposed to COM
<Assembly: Guid("84838924-1931-4C0A-BB23-D4E4BFABAD96")>

' Version information for an assembly consists of the
following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the
Build and Revision Numbers
' by using the '*' as shown below:
 
P

Peter Huang

Hi ,

That seems to a complex project. Your project doesn't work on my machine. (
I can not compile it)
After I code review, I did not find anything special which will cause the
problem.
Based on my understanding, you call the COM+ component in one thread in a
loop.

Here is my demo test, you may have a look to see if this code works on you
machine.

Dim o
set o = CreateObject("BankComponent.Account")
Dim i
i = 0
While i < 10
msgbox o.sqrt(i)
i = i + 1
Wend

Imports System.EnterpriseServices
Imports System.Runtime.CompilerServices
Imports System.Reflection
Imports System.Runtime.InteropServices

Namespace BankComponent
<Transaction(TransactionOption.Required),
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class Account
Inherits ServicedComponent
Dim m_count As Integer
Shared s_count As Integer
Public Sub New()
MyBase.New()
m_count = System.Threading.Interlocked.Increment(s_count)
End Sub
<AutoComplete()> _
Public Function Sqrt(ByVal x As Integer) As Integer
Sqrt = x * x
' Updates the database; no need to call SetComplete.
' Calls SetComplete automatically if no exception is generated.
End Function
End Class
End Namespace

Since it seems a large project, for such big code review has beyond the
newsgroup support field.
For more detailed code review I suggest you call Microsoft Product Support
Services (PSS) for further help.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top