MTS调试问题,请问高手,非高手莫看

zzao 2000-08-18 05:22:00
Public Function Add(myval strID as string,strName as string)
Dim conn as ADODB.connection
......
......
conn.Execute strSQL
Getobjectcontext.setcomplete
Exit Function
ErrorHandler:
IF Not conn is Nothing then
Set conn=Nothing
Endif
Getobjectcontext.Setabort

编译生成Mytest.dll 后,在我本机的Transaction Server Exploer上双击我的计算机
增加一软件包,然后安装新组件选 Mytest.dll加入。
然后在VB中增加一测试工程,添加对 Mytest的引用,并输入如处代码
dim objUsers as myTest.Users
Set objUsers = CreateObject("Mytest.Users"
objUsers.Add "0001","AAAA"

运行后,出现错误 Run_time Error "91"
"object variable or with block variable not set"
我设置断点跟踪
发现问题出在COM中
Getobjectcontext.Setcomplete 行。

难道我的这种测试方法有错误吗?一定要将组件安装到服务器的软件包中才能创建对象吗?

能不能教我怎样正确地测度MTS组件。
我的E-Mail:ZZAO@21CN.COM
...全文
128 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xguoz 2000-08-18
  • 打赏
  • 举报
回复
我认为原程序当中Getobjectcontext的使用有问题,应该如下:

function Add(...)

dim objCtx as ObjectContext
set objCtx=Getobjectcontext

dim cnnADO as object
set cnnADO=objCtx.CreateInstance("ADODB.Connection")

......

objCtx.SetComplete
set objCtx=nothing
exit function
ErrorHandle:
......
objCtx.SetAbort
set objCtx=nothing

如果是需要使用MTS,则使用objCtx.CreateInstance创建对象是应该的
objCtx在事务最开始的时候就要获得
原程序出错的原因是:Getobjectcontext返回的是对象指针,自身是没有使用方法的
xlzhou 2000-08-18
  • 打赏
  • 举报
回复
When developing Visual Basic components to run under control of Microsoft
Transaction Server (MTS), if your object uses ObjectContext, you may encounter
the following error when trying to debug them within the Visual Basic
environment:

Run-Time Error '91': Object variable or with block variable not set.

This article describes how to configure Visual Basic to allow you to debug these
components using the special debug version of GetObjectContext.

There are two ways to avoid this error when writing Visual Basic components. The
first is to configure Visual Basic to use a special version of the object
context. The second way is to use the Microsoft Developer Studio environment.

MORE INFORMATION
================

To facilitate application debugging using Visual Basic, you can debug a
component that uses ObjectContext by enabling a special version of the object
context. This debug-only version is enabled by creating the following registry
key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction

Server\Debug\RunWithoutContext

Steps to Create the Registry Key
--------------------------------

1. Start Regedit and locate the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction Server

2. Select the Transaction Server key, right-click the selection and choose New.
Next, choose Key and then name this new key Debug.

3. Now, select the Debug key, right-click and then choose New. Next, choose Key
and then name this new key RunWithoutContext.

Now that this registry entry is present on your computer, you should now be able
to run your MTS component using Visual Basic.

NOTE: When running in debug mode, none of the functionality of MTS is enabled.
GetObjectContext returns the debug ObjectContext rather than returning Nothing.

When running in this debug mode, the ObjectContext operates as follows:

- ObjectContext.CreateInstance - Calls COM CoCreateInstance (no context flows,
no transactions, and so on).</ITEM>

- ObjectContext.SetComplete - No effect.

- ObjectContext.SetAbort - No effect.

- ObjectContext.EnableCommit - No effect.

- ObjectContext.DisableCommit - No effect.

- ObjectContext.IsInTransaction - Returns FALSE.

- ObjectContext.IsSecurityEnabled - Returns FALSE.

- ObjectContext.IsCallerInRole - returns TRUE (same as normal when
IsSecurityEnabled is FALSE).

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧