PowerShell和VB6 COM +模块:对象变量或未设置块变量

时间:2015-03-09 20:50:40

标签: powershell com vb6

我正在尝试使用powershell在我的系统中进行自动测试,但是该系统的30%是通过COM使用的VB6模块。一些os这些模块使用模块内部为全局变量的私有变量。使用不使用这些变量的VB6函数,一切正常,但是依赖于这些“私有全局变量”的函数,我得到的错误是“对象变量或未设置块变量”。不幸的是,迁移这个VB6代码不会在短期内发生。

这是遗留代码的一部分:

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 1  'NoTransaction
END
Attribute VB_Name = "Data"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Private oConn        As ADODB.Connection
Private oRs          As ADODB.Recordset

Public Function rsOperadora(ByVal sUser As String, _
                             ByVal sPassword As String, _
                             ByVal sIP As String, _
                             ByVal sSystem As String, _
                             ByVal sModule As String)


    Dim sSql As String

    sSql = "select * from operator"


    Call Connect(sUser, sPassword, sSystem, sModule, sIP)

    oRs.CursorType = adOpenStatic
    oRs.CursorLocation = adUseClient
    oRs.Open sSql, oConn, , adLockBatchOptimistic
    oRs.ActiveConnection = Nothing

    Set rsOperadora = oRs

    Set oConn = Nothing

End Function

我试图做的事情:

PS E:\aazevedo> $tsdb = New-Object -ComObject "TSDB.Data"
PS E:\aazevedo> $tsdb.rsOperadora

OverloadDefinitions
-------------------
Variant rsOperadora (string, string, string, string, string)



PS E:\aazevedo> $tsdb.rsOperadora("ADMIN","8482867D8B958F0E","","DESENV11","")
Exception calling "rsOperadora" with "5" argument(s): "Object variable or With block variable not set"
At line:1 char:1
+ $tsdb.rsOperadora("ADMIN","8482867D8B958F0E","","DESENV11","")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

PS E:\aazevedo> $oRs = New-Object -ComObject "ADODB.Recordset"
PS E:\aazevedo> $tsdb.rsOperadora("ADMIN","8482867D8B958F0E","","DESENV11","")
Exception calling "rsOperadora" with "5" argument(s): "Object variable or With block variable not set"
At line:1 char:1
+ $tsdb.rsOperadora("ADMIN","8482867D8B958F0E","","DESENV11","")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

PS E:\aazevedo> oRs = New-Object -ComObject "ADODB.Recordset"
oRs : The term 'oRs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ oRs = New-Object -ComObject "ADODB.Recordset"
+ ~~~
    + CategoryInfo          : ObjectNotFound: (oRs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

在此示例中,函数Connect使用ADO打开数据库连接,分配给变量oConn。

我认为我的问题是变量oRs。

在ASP Classic内部,这个模块可以工作。

PS:抱歉我的英语很差。

0 个答案:

没有答案