I have created 2 stored procedures using pervasive's Control Center. When I attempt to open a recordset using ADO, with a valid connection object, I get: 3704 - The operation requested by the application is not allowed if the object is closed.
Since there are several legacy Access databases that query the same tables for similar data, I would like to run these as stored procedures. Where am I going wrong?
Here is the code:
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim comIndust As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim rsIndust As New ADODB.Recordset
Dim strIndust As String
Dim i As Integer
On Error GoTo testErrHand
'Create connection object
With cn
.CursorLocation = adUseServer
.Open "Provider=MSDASQL.1;Persist Security Info=True;Data Source=Indust"
End With
'Verify connection works
strIndust = "Select * from OcOrder"
rsIndust.Open strIndust, cn, adOpenForwardOnly
Do While Not rsIndust.EOF
Debug.Print rsIndust(0), rsIndust(1)
rsIndust.MoveNext
Loop
'Create command object
With comIndust
.ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "TestOcOrder"
End With
'Run stored procedure
Set rs = comIndust.Execute
'Open recordset
rs.MoveFirst
For i = 1 To 10
Debug.Print rs(0), rs(1)
rs.MoveNext
Next i
Set Adodc1.Recordset = rs
Set DataGrid1.DataSource = Adodc1
TestExit:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
testErrHand:
MsgBox Err.Number & "-" & Err.Description
Resume TestExit
Since there are several legacy Access databases that query the same tables for similar data, I would like to run these as stored procedures. Where am I going wrong?
Here is the code:
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim comIndust As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim rsIndust As New ADODB.Recordset
Dim strIndust As String
Dim i As Integer
On Error GoTo testErrHand
'Create connection object
With cn
.CursorLocation = adUseServer
.Open "Provider=MSDASQL.1;Persist Security Info=True;Data Source=Indust"
End With
'Verify connection works
strIndust = "Select * from OcOrder"
rsIndust.Open strIndust, cn, adOpenForwardOnly
Do While Not rsIndust.EOF
Debug.Print rsIndust(0), rsIndust(1)
rsIndust.MoveNext
Loop
'Create command object
With comIndust
.ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "TestOcOrder"
End With
'Run stored procedure
Set rs = comIndust.Execute
'Open recordset
rs.MoveFirst
For i = 1 To 10
Debug.Print rs(0), rs(1)
rs.MoveNext
Next i
Set Adodc1.Recordset = rs
Set DataGrid1.DataSource = Adodc1
TestExit:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
testErrHand:
MsgBox Err.Number & "-" & Err.Description
Resume TestExit