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\RunWithoutContextSteps to Create the Registry Key
--------------------------------1. Start Regedit and locate the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction Server2. 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).
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\RunWithoutContextSteps to Create the Registry Key
--------------------------------1. Start Regedit and locate the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction Server2. 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).
set objCtx=Getobjectcontextdim 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返回的是对象指针,自身是没有使用方法的