Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 22nd, 2006, 03:53 AM
Registered User
 
Join Date: May 2006
Location: Tapah, Perak, Malaysia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default COM+ transaction object

Hi,

I would like to know how to retain the object property value in visual basic 6.0 when COM+ transaction object either SetComplete is invoked?


Case study with sample code:
1. Create a class to store the property values, called clsOprPropertiesBag.
---------------------------------------------------------------------------------------------
‘clsOprPropertiesBag.cls to store UserName and Password
Option Explicit
Private mstrUserName As String
Public Sub SetLoginBag(ByVal vstrUserName As String, Optional ByVal vstrPassword As String)
Me.UserName = vstrUserName
Me.Password = vstrPassword
End Sub
'UserName
Public Property Get UserName() As String
UserName = mstrUserName
End Property
Public Property Let UserName(ByRef vstrUserName As String)
mstrUserName = vstrUserName
End Property
'Password
Public Property Get Password() As String
Password = mstrPassword
End Property
Public Property Let Password(ByRef vstrPassword As String)
mstrPassword = vstrPassword
End Property
------------------------------------------------------------------------------------------

2. The clsInterfaceUser Class in data access layer Implements the ObjectControl and declare ObjectContext for com+ use. A Public module level object mobjOperator is declared and set instance of clsOprPropertiesBag when initialize the class.
-----------------------------------------------------------------------------------------
‘clsInterfaceUser
Implements ObjectControl
Private mobjCtx As ObjectContext
Public mobjOperator As clsOprPropertiesBag

Private Sub Class_Initialize()
Set mobjOperator = CreateObject("clsOprPropertiesBag")
End Sub
------------------------------------------------------------------------------------------

3. Add in standard MTS coding into clsInterfaceUser.
--------------------------------------------------------------------------------------
Private Sub ObjectControl_Activate()
Set mobjCtx = GetObjectContext()
End Sub
Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = False
End Function
Private Sub ObjectControl_Deactivate()
Set mobjCtx = Nothing
End Sub
----------------------------------------------------------------------------------------------

4. Assume the clsInterfaceUser has two functions, namely GenerateSQL and OpenRecordSet.
----------------------------------------------------------------------------------------------
‘GenerateSQL
Public Function GenerateSQL(…) As String
Dim strSQL As String
If Len(Trim(strProperties)) > 0 Then
strSQL = IIf(blnDistinct, "SELECT DISTINCT " & strProperties & " FROM " & strDataSource, _
"SELECT " & strProperties & " FROM " & strDataSource)
Else
strSQL = IIf(blnDistinct, "SELECT DISTINCT * FROM " & strDataSource, "SELECT * FROM " & strDataSource)
End If
If Len(Trim(strFilter)) > 0 Then
strSQL = strSQL & " WHERE " & strFilter
End If
If Len(Trim(strGroup)) > 0 Then
strSQL = strSQL & " GROUP BY " & strGroup
End If
If Len(Trim(strSort)) > 0 Then
strSQL = strSQL & " ORDER BY " & strSort
End If
GenerateSQL = strSQL
If gblnCOMPLUSFlag Then
mobjCtx.SetComplete
End If
End Function

‘OpenRecordSet
Public Function OpenRecordset(…) As ADODB.Recordset
Dim rstQuery As ADODB.Recordset
Dim strConnection As String
Dim cnnQuery As ADODB.Connection
Dim strSQLStmt As String
Const cstrIsolationDirtyRead As String = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"
mstrConnect = GetDBConnectString(vstrThisPropertyCode)
strConnection = mstrConnect
Set rstQuery = New ADODB.Recordset
With rstQuery
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.CursorType = adOpenStatic
End With
Set cnnQuery = New ADODB.Connection
With cnnQuery
.ConnectionTimeout = 150 'default 15
.CommandTimeout = 300 'default 30
.CursorLocation = adUseClient
If cnnQuery.State = adStateOpen Then
cnnQuery.Close
End If
.Open strConnection
Set rstQuery = cnnQuery.Execute(strSQLStmt)
End With
Set rstQuery.ActiveConnection = Nothing
Set OpenRecordset = rstQuery
Set rstQuery = Nothing
If cnnQuery.State = adStateOpen Then
cnnQuery.Close
End If
Set cnnQuery = Nothing
If gblnCOMPLUSFlag Then
mobjCtx.SetComplete
End If
End Function
----------------------------------------------------------------------------------------------

5. Assume a business layer create the instance of clsInterfaceUser called objInterfaceUserDAL and assign the mobjOperator property User Name to “htkok”.
----------------------------------------------------------------------------------------------
Set objInterfaceUserDAL = CreateObject("clsInterfaceUser")
Set objInterfaceUserDAL.mobjOperator.SetLoginBag(“ht kok”)
----------------------------------------------------------------------------------------------

6. The problem is when calling two functions, namely GenerateSQL and OpenRecordSet, the mobjOperator property User Name of the second function will become empty string.
------------------------------------------------------------------------------------------------
strSql = objInterfaceUserDAL.GenerateSQL(…) à UserName = “htkok”
Set rs = objInterfaceUserDAL.OpenRecordset(…) à UserName = “” [Empty]
----------------------------------------------------------------------------------------------

7. The situation only happen when the gblnCOMPLUSFlag flag set to True. If the flag set to true, SetComplete and SetAport will be process.
----------------------------------------------------------------------------------------------
If gblnCOMPLUSFlag Then
mobjCtx.SetComplete
End If
--------------------------------------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old May 24th, 2006, 03:07 AM
Friend of Wrox
Points: 687, Level: 9
Points: 687, Level: 9 Points: 687, Level: 9 Points: 687, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamilnadu, India.
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

AS OF MY KNOWLEDGE,

When you use, SetComplete, the object is deactivited. So it loses its state.

So, what I say is, at the POINT:6 (what you have)

A> strSql = objInterfaceUserDAL.GenerateSQL(…) à UserName = “htkok”
B> Set rs = objInterfaceUserDAL.OpenRecordset(…) à UserName = “” [Empty]

A, is needed before Executing B. So why dont you call A in the B itsself
and try to USE "SetComplete" once by mixing both of them. Here after executing
A, you are calling SetComplete and in B also you are calling SetComplete, I guess
its like a over work on MTS,

Try making it as a batch, and mix up A and B, USE one SetComplete, and check,
might be this will help in fixing.

FOR EX:-
Consider you open a connection object with DB
then you will have to fetch the data from DB,
So you use Recordset, then you will have some
data need to inserted into 2 or three tables
so you use the same connection object with
command object. Here you finish up the work
and finally you close the connection.

Its not like open the connection for fetching
the data, then close it then open again to
insert the data to one table and close it
and open it again for inserting to another
table... and so on.

Its like a batch, open ones finish up the
work and close it.

So do the same with mtsobject, open once
get all the data (what ever you want, i mean
input params,) call A and B one after the other
and use that "SetComplete" once. (like a batch
execution)

This was just an fare idea of mine.

Hope this helps.

With Regards,
Raghavendra Mudugal
Reply With Quote
  #3 (permalink)  
Old May 29th, 2006, 07:28 AM
Registered User
 
Join Date: May 2006
Location: Tapah, Perak, Malaysia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for you opinion.
Actually what I am showing is just part of my system.
Besides of the code shown, still got few part cause the same problem.
It is imposible for me to restudy whole system again and modify the code.

Anyway, I found a solution from Microsoft by using Share Property Group.
http://support.microsoft.com/kb/191235/en-us
http://support.microsoft.com/kb/267844/en-us

The share property group quite useful, but it usage is for share static property. What I need is dynamic property.
Now still facing problem on how to dynamically set the share property group for different section.

Hope someone can give me an answer.

Thanks.
Reply With Quote
  #4 (permalink)  
Old May 29th, 2006, 11:48 PM
Friend of Wrox
Points: 687, Level: 9
Points: 687, Level: 9 Points: 687, Level: 9 Points: 687, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamilnadu, India.
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, GOTCHA !!!

Chech this link
http://www.geocities.com/raghavendra_mudugal/mtschm.zip
(its an help on MTS SDK, which has two files .chm and .chi)

Open that .CHM file, in menu, select "GO" and "URL..."
a window appears which has a textbox in there. Copy the below
url and click "OK"
=========
mk:@MSITStore:C:\Program%20Files\Microsoft%20Visua l%20Studio\MSDN\2001JUL\1033\MTS.Chm::/hh/html/mtxpg08vb_4hnp.htm
=========

It will take to the "Sharing State" topic. If you give a deeper look,
you may find a way to fix the problem.

Hope this helps.


With Regards,
Raghavendra Mudugal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transaction Management azmatazz Biztalk 0 April 28th, 2005 07:17 AM
Transaction Logs kilika SQL Server 2000 17 September 30th, 2004 09:26 AM
Another Transaction question Gert SQL Server 2000 8 March 16th, 2004 02:44 PM
how to use Transaction ? locka ADO.NET 0 August 12th, 2003 08:48 PM
Transaction Log ColdFusionRO SQL Server 2000 3 July 16th, 2003 01:47 PM



All times are GMT -4. The time now is 05:57 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.