用VB6创建MTS组件

2016-01-29 18:19 9 1 收藏

用VB6创建MTS组件,用VB6创建MTS组件

【 tulaoshi.com - ASP 】

  随便贴贴,学过VB的人都应该知道的,不好意思。
'**********************************************************************************************
'                 MTS VB6 COM Component Template - by Michael Gonzalez
'**********************************************************************************************
'(1) You must create a reference to the Microsoft Transaction Server Type Library (mtxas.dll).
'    If using Windows 2000, choose the COM+ Services Library (comsvcs.dll) instead.
'(2) Set your ClassModule's MTSTransactionMode property to 2 - RequiresTransaction
'    Note: ONLY use 2 - Requires Transaction if you plan on using the component with an MSDTC-
'    compliant Resource Manager such as MSMQ or SQL Server - OTHERWISE, use
'    1 - No Transactions
'(3) Make sure your project's Unattended Execution property is checked
'(4) Make sure your project's Component Version Compatibility is set to Binary Compatibility
'**********************************************************************************************
'  ObjectControl implements the interface that is used by MTS when the object is
'   activated and/or deactivated - this happens when you call one of the components's methods
'  The ObjectControl implementation makes use of three procedures:
'   1) ObjectControl_Activate
'   2) ObjectControl_CanBePooled
'   3) ObjectControl_Deactivate
'**********************************************************************************************
Implements ObjectControl

Dim objOC As ObjectContext

Public Sub Something()
    'This is a user-defined procedure/method
    'The ObjectContext Object is returned by GetObjectContext
    
    On Error GoTo Abort
    
    '*******************************************************
    '       Perform whatever you want in this area
    '       Visual Basic 6 stuff goes here
    '       The Something() procedure/method is just
    '       an example - you may use properties and other
    '       methods/procedures as well!
    '*******************************************************
    
Finished:
    objOC.SetComplete
        Exit Sub
Abort:
    objOC.SetAbort
        Err.Raise Err.Number, Err.Source, Err.Description
        Exit Sub
End Sub

Private Sub ObjectControl_Activate()
    'MTS invokes this procedure/method when the component/object is instantiated
    Set objOC = GetObjectContext()
    Exit Sub
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
    'This enables MTS object pooling (not currently supported my MTS 2.0)
    ObjectControl_CanBePooled = True
End Function

Private Sub ObjectControl_Deactivate()
    'MTS invokes this procedure/method right before the component/object is released
    Set objOC = Nothing
    Exit Sub
End Sub

 

来源:https://www.tulaoshi.com/n/20160129/1505327.html

延伸阅读
在VB6的报表使用过程中,我们会发现这样的一个问题,那就是报表中的数据只能读一次,不管你的库中字段增加也好,删除也好,以及让它显示新的查询结果等,它都不会记变。经过查资料才搞清楚,原来是DataEnvironment的问题.原来,只要Command对象中含有数据记录集合,它就不会重新执行SQL语句,就算是把新的查询语句给DataEnvironment后它也不会执行,解决...
在VB6中动态创建使用ADO控件访问数据库 使用ADO控件可以方便的在VB6中访问ODBC数据库,但是通过直接放置ADODS控件来获得ADO的数据连接比较麻烦,我们可以在VB工程中创建一个公共数据模块,将ADO控件的初始化、建立连接、关闭连接等操作都写到函数中,这样就可以在工程的其他模块中共享调用这个ADO连接。 一次完整的ADO调用操作分为如下几个步骤...
我们在玩《仙剑奇侠传》时,要是不能保存数据,那么非得挑灯夜战三昼夜才能玩完,可见数据存储之重 要性。爱好编程的CFAN是不会放过数据文件的,下面跟着我驰骋吧!我们先吃一个哈密瓜,开门即来编一传统的比较有代表性的程序,不可不看的哟! 程序分为一个表单cfanvb.frm,一个模块cfanvb.bas。一个表单程序。程序的表单中有五个命令按...
  和.Net 中不同,VB6 中默认是使用 ByRef 来传递参数了,看来似乎没有什么可以优化得地方。 可是,实际上 如果你调用 API 得话,从 API浏览器复制下来得代码却是 强制使用 ByVal 传参得 这就给了我们优化得机会。 我又重新使用该代码 分别测试了一下 ByRef ,ByVal 得区别,结果很振奋: ByRef 比 ByVal 提高了16倍 代码如下,插入Comb...
嘿嘿,看到这个题目,想必吓了一大跳吧,或者是摆出一副不相信的表情?不用着急,请听我慢慢道来。 话说这个VB6,很是无耻,居然内置了支持Unicode的功能,也就是说,当你读入一个字符串时,它根据本地缺省语言的对应关系将之转换为Unicode,输出时,再从Unicode转换为本地编码。一方面,它当然方便啦,随便出个什么语言的版本都好方便的,...

经验教程

478

收藏

49
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部