1

我正在使用 windows server 2008 R2 64 位和 IIS 7.5 并托管一个经典的 asp(32 位)网站并在 COM 服务器(也有 windows server 2008 R2 64 位)上调用 COM 组件。但收到错误“权限被拒绝”,错误代码为 800A0046。

Set oDictAOGroup = CreateObject("Scripting.Dictionary")
oDictAOGroup.Add "1000", "5"
oUser.fn_Update_AO_Groups(oDictAOGroup)

asp 网站服务器使用 DCOM 与 COM 服务器进行通信。在 asp 网站服务器代理是由 COM 服务器类创建的。

我创建了一个测试函数并将值传递给该函数,然后代码工作得很好。

oUser.fn_Update_AO_Groups_Test1("1000", "21")

但是当尝试传递 Scipting.Dictionary 对象时,会引发权限被拒绝错误。我为此搜索了很多,但徒劳无功。

函数的代码是

Public Function fn_Update_AO_Groups(vntAODict As Variant)

On Error GoTo ErrorHandler

Dim oADOConnect As AMLCONNECT_V2.clsConnect
Dim oADOConn        As ADODB.Connection
Dim oADOCmd         As ADODB.Command
Dim vntKey          As Variant

    If Not objContext Is Nothing Then
        Set oADOConnect = objContext.CreateInstance("AMLCONNECT_V2.clsConnect")
        Set oADOCmd = objContext.CreateInstance("ADODB.Command")
    Else
        Set oADOConnect = New clsConnect
        Set oADOCmd = New ADODB.Command
    End If

    If IsObject(vntAODict) Then
        If oADOConnect.OpenADOConnection(oADOConn) Then
            With oADOCmd
                .CommandText = "Sp_Upd_AOGroups"
                .CommandType = adCmdStoredProc
                .Parameters.Append .CreateParameter("AO_ID", adInteger, adParamInput)
                .Parameters.Append .CreateParameter("Email_Group_ID", adInteger, adParamInput)
                Set .ActiveConnection = oADOConn
            End With
            'Execute stored procedure for each item in the dictionary
            For Each vntKey In vntAODict.Keys
                oADOCmd.Parameters("AO_ID").Value = vntKey
                oADOCmd.Parameters("Email_Group_ID").Value = vntAODict(vntKey)
                oADOCmd.Execute
            Next
        End If
    End If

TidyUp:

    Set oADOConn = Nothing
    Set oADOCmd = Nothing
    Set oADOConnect = Nothing

Exit Function

ErrorHandler:
    Dim ErrHandler As AMLCONNECT_V2.clsConnect

    If Not objContext Is Nothing Then
        Set ErrHandler = objContext.CreateInstance("AMLCONNECT_V2.clsConnect")
    Else
        Set ErrHandler = New AMLCONNECT_V2.clsConnect
    End If

    m_sErrorMessage = "Error Number: " + CStr(Err.Number) + "<BR>" + "Description: " + ErrHandler.LogError(Err.Number, Err.Description, "MODULE: AMLADMIN_V2.clsUsers", "FUNCTION:fn_Update_AO_Groups", errError, errVB, errDatabase, "")

    If Not ErrHandler Is Nothing Then Set ErrHandler = Nothing

    GoTo TidyUp:

End Function

任何人都可以为此提出补救措施吗?

函数接受字符串的代码

Public Function fn_Update_AO_Groups_Test1(strKey As String, strValue As String)

On Error GoTo ErrorHandler

Dim oADOConnect As AMLCONNECT_V2.clsConnect
Dim oADOConn        As ADODB.Connection
Dim oADOCmd         As ADODB.Command
Dim vntKey          As Variant

Dim ErrHandlerTest As AMLCONNECT_V2.clsConnect

    If Not objContext Is Nothing Then
        Set oADOConnect = objContext.CreateInstance("AMLCONNECT_V2.clsConnect")
        Set oADOCmd = objContext.CreateInstance("ADODB.Command")

    Else
        Set oADOConnect = New clsConnect
        Set oADOCmd = New ADODB.Command

    End If

            If oADOConnect.OpenADOConnection(oADOConn) Then
                With oADOCmd
                    .CommandText = "Sp_Upd_AOGroups"
                    .CommandType = adCmdStoredProc
                    .Parameters.Append .CreateParameter("AO_ID", adInteger, adParamInput)
                    .Parameters.Append .CreateParameter("Email_Group_ID", adInteger, adParamInput)
                    Set .ActiveConnection = oADOConn
                End With
                'Execute stored procedure for each item in the dictionary
                    oADOCmd.Parameters("AO_ID").Value = strKey
                    oADOCmd.Parameters("Email_Group_ID").Value = strValue
                    oADOCmd.Execute
            End If
TidyUp:

    Set oADOConn = Nothing
    Set oADOCmd = Nothing
    Set oADOConnect = Nothing

Exit Function

ErrorHandler:
    Dim ErrHandler As AMLCONNECT_V2.clsConnect

    If Not objContext Is Nothing Then
        Set ErrHandler = objContext.CreateInstance("AMLCONNECT_V2.clsConnect")
    Else
        Set ErrHandler = New AMLCONNECT_V2.clsConnect
    End If

    m_sErrorMessage = "Error Number: " + CStr(Err.Number) + "<BR>" + "Description: " + ErrHandler.LogError(Err.Number, Err.Description, "MODULE: AMLADMIN_V2.clsUsers", "FUNCTION:fn_Update_AO_Groups", errError, errVB, errDatabase, "")

    If Not ErrHandler Is Nothing Then Set ErrHandler = Nothing

    GoTo TidyUp:

End Function

谢谢, 瓦巴夫

4

3 回答 3

0

使用Call oUser.fn_Update_AO_Groups(oDictAOGroup)oUser.fn_Update_AO_Groups oDictAOGroup不使用括号。

于 2012-06-05T07:40:01.623 回答
0

试试这些签名:

Public Function fn_Update_AO_Groups(ByVal vntAODict As Variant) 

或者

Public Function fn_Update_AO_Groups(ByVal vntAODict As Scripting.Dictionary)

如果您允许默认ByRef设置占上风,您需要更多的编组代码。还提供预期的显式类型也为编组代码提供了更多选项。这些更改可能足以允许您进行预期的操作。

如果失败了,我会重新考虑这种方法,我更愿意将 XML 字符串传递给 SP。这提供了最大的灵活性,允许对 SQL 和 ASP 的代码更改以影响新的需求,而无需重新编译和部署新的二进制文件。

于 2012-06-05T11:09:00.417 回答
0

评论太长了,所以虽然这不是完整的答案,但它可能会让你朝着正确的方向前进。

首先,我注意到字段类型是整数,而您的字典键和值是字符串。因此,首先尝试通过将函数中的代码更改为:

oADOCmd.Parameters("AO_ID").Value = CLng(vntKey)
oADOCmd.Parameters("Email_Group_ID").Value = CLng(vntAODict(vntKey))

如果仍然是相同的错误,我需要知道当您将两个参数显式传递给函数而不是字典时,完全相同的代码是否可以正常工作?

想到的另一件事是您的错误处理可能出了问题,尝试将其删除以进行调试,看看您是否收到更有意义的错误消息。

于 2012-06-05T07:03:00.597 回答