利用RDS可以对远程ACCESS数据库执行查询,但为什么不能执行删除和插入的操作呢??

解决方案 »

  1.   

    服务器是2000Server的,代码应该没有问题,查询操作可以返回值。可能原因在服务器的配置上,请高手指点!!!
      

  2.   

    这是在服务器端运行的DLL文件,用来执行客户端发送的SQL语句,客户端传入的查询语句可以得到正确结果,但删除和插入不行。
    Option Explicit
    Private cn As ADODB.ConnectionPrivate rst As ADODB.RecordsetPublic Function Getdata(UserID As String, Password As String, sqlstr As String) As Recordset
        ' Create connection object.
        MakeConnection UserID, Password
        Set rst = New ADODB.Recordset
        With rst
            .CursorLocation = adUseClient
            .Source = sqlstr
            Set .ActiveConnection = cn
            .CursorType = adOpenStatic
            .LockType = adLockOptimistic
            .Open
        End With
        On Error Resume Next
        Set rst.ActiveConnection = Nothing
        Set Getdata = rst
    End FunctionPublic Function MakeConnection(Optional UserID As String, _
    Optional Password As String) As String
        ' Create the connection object.
        Set cn = New ADODB.Connection
        On Error GoTo ConnectErr
        With cn
            .CursorLocation = adUseClient
            
            .ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" & _
            "Dbq=C:\inetpub\wwwroot\ick.mdb;" & _
            "Uid=" & UserID & ";Pwd=" & Password
        
            .Open
        End With
        ' Assuming no errors occurred.
        MakeConnection = True
        Exit Function
        ' When errors occur, trap them below.
    ConnectErr:
        Dim i As Integer
        Dim sErrors As String
        sErrors = Err.Number & ": " & Err.Description
        If cn.Errors.Count > 0 Then
            For i = 0 To cn.Errors.Count - 1
                ' Handle errors here.
                sErrors = sErrors & cn.Errors(i).Number & _
                ": " & cn.Errors(i).Description & vbCrLf
            Next i
        End If
        MakeConnection = sErrors
        Exit Function
    End FunctionPrivate Sub Class_Terminate()
        Set rst = Nothing
        
        Set cn = Nothing
    End Sub
      

  3.   

    用cn.Execute来执行非查询操作试试:Public Function Getdata(UserID As String, Password As String, sqlstr As String) As Recordset
        Dim strOp As String
        ' Create connection object.
        MakeConnection UserID, Password
        strOp = Left(Trim(sqlstr), InStr(Trim(sqlstr), Space(0)) - 1) '判断sql语句是进行什么操作
        
        If InStr("INSERT,DELETE,UPDATE", UCase(Trim(strOp))) Then '非查询操作,用cn.Execute来执行
            cn.Execute sql
        Else '查询操作用rst.Open来执行
            Set rst = New ADODB.Recordset
            With rst
                .CursorLocation = adUseClient
                .Source = sqlstr
                Set .ActiveConnection = cn
                .CursorType = adOpenStatic
                .LockType = adLockOptimistic
                .Open
            End With
        End If
        On Error Resume Next
        Set rst.ActiveConnection = Nothing
        Set Getdata = rst
    End FunctionPrivate Sub Class_Terminate()
        If rst.State <> adStateClosed Then rst.Close
        If cn.State <> adStateClosed Then cn.Close
        Set rst = Nothing
        Set cn = Nothing
    End Sub
      

  4.   

    More compact code:Public Function ExecuteSQL(Optional ByVal SSQL As String, _
                               Optional AdoCmd As ADODB.Command) As Boolean    On Error GoTo ErrorHandlerDim oCmd  As ADODB.Command
        Set oCmd = New ADODB.Command
    Dim oRS As ADODB.Recordset    ExecuteSQL = False    If AdoCmd Is Nothing Then
            Set oCmd.ActiveConnection = moADODBConnection
            With oCmd
                .CommandType = adCmdText
                .CommandText = SSQL
            End With
            oCmd.Execute , , adExecuteNoRecords
        Else
            Set oCmd = AdoCmd
            Set oCmd.ActiveConnection = moADODBConnection
            oCmd.Execute , , adExecuteNoRecords
            Set oRS = moADODBConnection.Execute("SELECT @@Identity", , adCmdText)
        End If    ExecuteSQL = True
        Set oCmd = NothingExit FunctionErrorHandler:
        '    gErrorHandler Err.Number, Err.Description, OBJNAMEEnd Function
      

  5.   

    解决了,是因为每次修改IIS后,必须重新启动IIS就OK了,