MaBen
Jul 13th, 2000, 02:51 PM
I am using SQL server 7.0, VB6 sp4 and ADO 2.5.
When I'm running this code, witch call two Stored Procedures, first is a simple Select and the second is a Delete, I get an error after The requery "This operation is not authorized if the object is closed." my RecordSet is closed. Why???
Anybody help!
Dim cnnDossier As ADODB.Connection
Dim cmdDossier As ADODB.Command
Dim rsKM As ADODB.Recordset
Dim rsTemp As ADODB.Recordset
Set cnnDossier = New ADODB.Connection
' Création de la conection
With cnnDossier
.CursorLocation = adUseClient
.Open "Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Dossiers;Data Source=Serveur"
End With
Set cmdDossier = New ADODB.Command
Set rsKM = New ADODB.Recordset
With cmdDossier
Set .ActiveConnection = cnnDossier
.CommandText = "sproc_CompHeuresKM_UserName_User"
.CommandType = adCmdStoredProc
End With
rsKM.Open cmdDossier, , adOpenDynamic, adLockOptimistic
Debug.Print "Record count after open = " & rsKM.RecordCount
With cmdDossier
Set .ActiveConnection = cnnDossier
.CommandText = "sproc_CompHeuresKM_Delete_User"
.CommandType = adCmdStoredProc
.Parameters("@Numero_1") = x.Numero
End With
Set rsTemp = New ADODB.Recordset
rsTemp.Open cmdDossier, , adOpenDynamic, adLockOptimistic
Set rsTemp = Nothing
Debug.Print "Record count after delete = " & rsKM.RecordCount
rsKM.Requery
Debug.Print "Record count after requery = " & rsKM.RecordCount 'Error message
' This operation is not authorized if the object is closed.
Set rsKM = Nothing
Set cmdDossier = Nothing
Set cnnDossier = Nothing
When I'm running this code, witch call two Stored Procedures, first is a simple Select and the second is a Delete, I get an error after The requery "This operation is not authorized if the object is closed." my RecordSet is closed. Why???
Anybody help!
Dim cnnDossier As ADODB.Connection
Dim cmdDossier As ADODB.Command
Dim rsKM As ADODB.Recordset
Dim rsTemp As ADODB.Recordset
Set cnnDossier = New ADODB.Connection
' Création de la conection
With cnnDossier
.CursorLocation = adUseClient
.Open "Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Dossiers;Data Source=Serveur"
End With
Set cmdDossier = New ADODB.Command
Set rsKM = New ADODB.Recordset
With cmdDossier
Set .ActiveConnection = cnnDossier
.CommandText = "sproc_CompHeuresKM_UserName_User"
.CommandType = adCmdStoredProc
End With
rsKM.Open cmdDossier, , adOpenDynamic, adLockOptimistic
Debug.Print "Record count after open = " & rsKM.RecordCount
With cmdDossier
Set .ActiveConnection = cnnDossier
.CommandText = "sproc_CompHeuresKM_Delete_User"
.CommandType = adCmdStoredProc
.Parameters("@Numero_1") = x.Numero
End With
Set rsTemp = New ADODB.Recordset
rsTemp.Open cmdDossier, , adOpenDynamic, adLockOptimistic
Set rsTemp = Nothing
Debug.Print "Record count after delete = " & rsKM.RecordCount
rsKM.Requery
Debug.Print "Record count after requery = " & rsKM.RecordCount 'Error message
' This operation is not authorized if the object is closed.
Set rsKM = Nothing
Set cmdDossier = Nothing
Set cnnDossier = Nothing