Link to home
Start Free TrialLog in
Avatar of mirghani
mirghani

asked on

RunTime Error

i implemented my Application using Com+, i'm getting this error:Run time error "3251": ....etc.
i checked this link:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q201716.
and i checked my code it contains the following:

Private Sub ObjectControl_Activate()
Set Cnn = New ADODB.Connection
Set Cmd = New ADODB.Command
On Error GoTo Err_Cnn
    Cnn.Open connstr
Exit Sub
Err_Cnn:
   ChkVal = 1
Set mV2 = GetObjectContext()
  End Sub


Public Function OpenRecordSet(spName As String, ParamArray AttachedParameters() As Variant) As ADODB.Recordset
'Dim MyRec As ADODB.Recordset
Set Rs = New ADODB.Recordset
Dim i As Long
If Rs.State = adStateOpen Then
   Rs.Close
End If
With Rs
    .CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .CursorLocation = adUseClient  '<-- Add this line
End With

On Error GoTo ERRORHANDLER
     Cmd.CommandTimeout = 3600
     Cmd.ActiveConnection = Cnn
     Cmd.CommandType = 4 'Stored Procedure
     Cmd.CommandText = Trim(spName)
        If UBound(AttachedParameters) >= 0 Then
            Cmd.Parameters.Refresh
            For i = 0 To UBound(AttachedParameters)
                Cmd.Parameters(i + 1).Value = AttachedParameters(i)
            Next i
        End If
     Rs.Open Cmd
     Set OpenRecordSet = Rs
     Exit Function
ERRORHANDLER:
    Set OpenRecordSet = Nothing
    End If
End Function

Private Sub ObjectControl_Deactivate()
    Set Cnn = Nothing
    Set Cmd = Nothing
    Set Rs = Nothing
    Set mV2 = Nothing
End Sub
........ i tried to comment the deactivate Sub as to keep the record connected but still i'm getting the error:-(
Any Help!!!!!
Regards Meer.
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mirghani
mirghani

ASKER

i tried the link but still:-(
if i set the CursorLocation=adUseServer it will not work at all!!!!!
any help.....?
Meer.
Do you know what line of code raises the error? And how are Cmd and Cnn declared?