简体   繁体   中英

Permission denied error when try use Scripting.Dictionary

I am using windows server 2008 R2 64-bit and IIS 7.5 and hosting a classic asp (32-bit) web site and invoking COM components on COM server (which too have windows server 2008 R2 64-bit). But getting a error "Permission denied" and error code is 800A0046.

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

asp website server uses DCOM to communicate with COM server. On asp web site server proxy is created of COM server classes.

I created a test function and passed the values to that function then code works perfectly fine.

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

But when try to pass Scipting.Dictionary object then permission denied error is raised. I have googled a lot for this but all in vain nothing much relevant.

Function's code is

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

Can any one suggest a remedy for this ?

code for function accepting string

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

Thanks, Vaibhav

Too long for comment, so while this is not full answer it might put you on right direction.

First, I noticed the field types are integer while your dictionary keys and values are string. So first try converting those by changing the code in the function to:

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

If still same error, I need to know if the exact same code works fine when you explicitly pass two parameters to the function instead of a dictionary?

Another thing that comes to mind is maybe something is going wrong with your error handling, try to remove it for sake of debug and see if you get more meaningful error message.

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

Try these signatures instead:

Public Function fn_Update_AO_Groups(ByVal vntAODict As Variant) 

or

Public Function fn_Update_AO_Groups(ByVal vntAODict As Scripting.Dictionary)

You demand far more of the marshalling code if you allow the default ByRef to prevail. Also providing the explict type expected gives marshalling code more options too. These changes may be enough to allow the operation you expect.

If that fails I would reconsider the approach, I prefer to pass XML strings through into the SPs. This gives greatest flexibility allowing code changes to SQL and ASP to effect a new requirement without recompilation and deployment of new binaries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM