Here's a copy of a simple application that opens a remote informix data base for the purpose of executing a store procedure that creates a record set. When I compile and run the application the connection gets opened successfully but the application fails upon execution of :
Set prm05 = cmdtmsSQL.CreateParameter("from_acct_yr_mon", adVarChar, adParamInput, from_acct_yr_mon).
I have attached the code. What I need is the cause or a way to determine the cause.
I'm new to VB - I'm sure it shows. Thanks
---------------
Option Explicit
Private Sub Form_Load()
On Error GoTo Err_Execute
' Dim parameters to be passed to the stored procedure
Dim comp As Integer
Dim v_co As Integer
Dim stor As Integer
Dim v_st As Integer
Dim from_acct_yr_mon As String
Dim from_acct_day As Integer
Dim to_acct_yr_mon As String
Dim to_acct_day As Integer
'Set up parameters for use in by stored procedure
Dim prm01 As ADODB.Parameter
Dim prm02 As ADODB.Parameter
Dim prm03 As ADODB.Parameter
Dim prm04 As ADODB.Parameter
Dim prm05 As ADODB.Parameter
Dim prm06 As ADODB.Parameter
Dim prm07 As ADODB.Parameter
Dim prm08 As ADODB.Parameter
' Dimension connections, commands, and recordset variables
' Dim ADODB.Connections
Dim Cnxntms As ADODB.Connection
'Dim Cnxnsds As ADODB.Connection
' Dim ADODB.Commands
Dim cmdtmsSQL As ADODB.Command
'Dim cmdsds As ADODB.Command
' Dim ADODB.Recordsets
Dim adotmsRS As ADODB.Recordset
'Dim adosdsRS As ADODB.Recordset
' Define area to catch errors
Dim Err As ADODB.Error
' Dim strSQLChange As String
Dim strSQLProc As String
Dim strtmsCnxn As String
'Dim strsdsCnxn As String
'Dim SQLProc As String
'Set up Proc String to accept the procedure and parameter fields
strSQLProc = "informix.sp_dly_rpt_sls"
' Set up trial parameters to pass
comp = 1
v_co = 1
stor = 962
v_st = 962
from_acct_yr_mon = "12/2004"
from_acct_day = 1
to_acct_yr_mon = "12/2004"
to_acct_day = 31
' Set connection strings
strtmsCnxn = "PROVIDER=MSDASQL;dsn=tms_rdb;uid=apple;pwd=pie;database=tms_rdb;"
'strsdsCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\ta\sales\sds.mdb;uid=admin;pwd=admin"
' Set Cnxn = New ADODB.Connection
Set Cnxntms = New ADODB.Connection
'Set Cnxnsds = New ADODB.Connection
' Create command object
' Set cmdChange = New adodb.Command
Set cmdtmsSQL = New ADODB.Command
'Set cmdsds = New ADODB.Command
' Cnxn.Open strCnxn
Cnxntms.Open strtmsCnxn
'Cnxnsds.Open strsdsCnxn
MsgBox "Connection opened"
'Set Command type and load with procedure name
cmdtmsSQL.CommandType = adCmdStoredProc
cmdtmsSQL.CommandText = strSQLProc
' Set cmdChange.ActiveConnection = Cnxn
Set cmdtmsSQL.ActiveConnection = Cnxntms
'Set cmdsds.ActiveConnection = Cnxnsds
'Set recordsets = New ADODB.Recordset
Set adotmsRS = New ADODB.Recordset
'Set adosdsRS = New ADODB.Recordset
'Create 8 input parameters for the stored procedure to be called
Set prm01 = cmdtmsSQL.CreateParameter("comp", adSmallInt, adParamInput, comp)
Set prm02 = cmdtmsSQL.CreateParameter("v_co", adSmallInt, adParamInput, v_co)
Set prm03 = cmdtmsSQL.CreateParameter("stor", adSmallInt, adParamInput, stor)
Set prm04 = cmdtmsSQL.CreateParameter("v_st", adSmallInt, adParamInput, v_st)
Set prm05 = cmdtmsSQL.CreateParameter("from_acct_yr_mon", adVarChar, adParamInput, from_acct_yr_mon)
' *******The preceeding "Set prm05 =...." causes the Runtime Error '91' message. I used the Vb debugger to isolate to the execution of this statement. Stop at Set prm05 - no error. Continue to >Set prm06 and you get the error. (the line rap in this statement is not in the source)
Set prm06 = cmdtmsSQL.CreateParameter("from_acct_day", adInteger, adParamInput, from_acct_day)
Set prm07 = cmdtmsSQL.CreateParameter("to_acct_yr_mon", adVarChar, adParamInput, to_acct_yr_mon)
Set prm08 = cmdtmsSQL.CreateParameter("to_acct_day", adInteger, adParamInput, to_acct_day)
cmdtmsSQL.Parameters.Append prm01
cmdtmsSQL.Parameters.Append prm02
cmdtmsSQL.Parameters.Append prm03
cmdtmsSQL.Parameters.Append prm04
cmdtmsSQL.Parameters.Append prm05
cmdtmsSQL.Parameters.Append prm06
cmdtmsSQL.Parameters.Append prm07
cmdtmsSQL.Parameters.Append prm08
' ExecuteCommand the procedure and return a complete record set from the stored procedure
ExecuteCommand cmdtmsSQL, adotmsRS
' Print report of new data
' Debug.Print _
' "Data in Titles table after executing the query"
Debug.Print "Records retrieved > " & adotmsRS.RecordCount
Debug.Print "Fields retrieved > " & adotmsRS.Fields.Count
Debug.Print "Stored procedure worked! Hopefully!"
' Clean up
' Cnxn.Close
Cnxntms.Close
' Cnxnsds.Close
Set Cnxntms = Nothing
' Set Cnxnsds = Nothing
Exit Sub
Err_Execute:
' Notify user of any errors that result from
' executing the query
If adotmsRS.ActiveConnection.Errors.Count >= 0 Then
For Each Err In adotmsRS.ActiveConnection.Errors
MsgBox "Error number: " & Err.Number & vbCr & _
Err.Description
Next Err
End If
' Clean up
If Not adotmsRS Is Nothing Then
If adotmsRS.State = adStateOpen Then adotmsRS.Close
End If
Set adotmsRS = Nothing
If Not Cnxntms Is Nothing Then
If Cnxntms.State = adStateOpen Then Cnxntms.Close
End If
Set Cnxntms = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
Public Sub ExecuteCommand(cmdTemp As ADODB.Command, rstTemp As ADODB.Recordset)
Dim Err As Error
' Run the specified Command object and trap for
' errors, checking the Errors collection
On Error GoTo Err_Execute
cmdTemp.Execute
On Error GoTo 0
Exit Sub
Err_Execute:
' Notify user of any errors that result from
' executing the query
If rstTemp.ActiveConnection.Errors.Count > 0 Then
For Each Err In rstTemp.ActiveConnection.Errors
MsgBox "Error number: " & Err.Number & vbCr & _
Err.Description
Next Err
End If
Resume Next
End Sub
Public Sub PrintOutput(rstTemp As ADODB.Recordset)
' Enumerate Recordset
Do While Not rstTemp.EOF
Debug.Print " " & rstTemp!Title & _
", " & rstTemp!Type
rstTemp.MoveNext
Loop
End Sub
'EndExecuteVB
Private Sub Text1_Change()
End Sub
Private Sub txtEndDate_Change()
End Sub
Private Sub txtStartDate_Change()
End Sub
Private Sub txtCorporateName_Change()
End Sub
Set prm05 = cmdtmsSQL.CreateParameter("from_acct_yr_mon", adVarChar, adParamInput, from_acct_yr_mon).
I have attached the code. What I need is the cause or a way to determine the cause.
I'm new to VB - I'm sure it shows. Thanks
---------------
Option Explicit
Private Sub Form_Load()
On Error GoTo Err_Execute
' Dim parameters to be passed to the stored procedure
Dim comp As Integer
Dim v_co As Integer
Dim stor As Integer
Dim v_st As Integer
Dim from_acct_yr_mon As String
Dim from_acct_day As Integer
Dim to_acct_yr_mon As String
Dim to_acct_day As Integer
'Set up parameters for use in by stored procedure
Dim prm01 As ADODB.Parameter
Dim prm02 As ADODB.Parameter
Dim prm03 As ADODB.Parameter
Dim prm04 As ADODB.Parameter
Dim prm05 As ADODB.Parameter
Dim prm06 As ADODB.Parameter
Dim prm07 As ADODB.Parameter
Dim prm08 As ADODB.Parameter
' Dimension connections, commands, and recordset variables
' Dim ADODB.Connections
Dim Cnxntms As ADODB.Connection
'Dim Cnxnsds As ADODB.Connection
' Dim ADODB.Commands
Dim cmdtmsSQL As ADODB.Command
'Dim cmdsds As ADODB.Command
' Dim ADODB.Recordsets
Dim adotmsRS As ADODB.Recordset
'Dim adosdsRS As ADODB.Recordset
' Define area to catch errors
Dim Err As ADODB.Error
' Dim strSQLChange As String
Dim strSQLProc As String
Dim strtmsCnxn As String
'Dim strsdsCnxn As String
'Dim SQLProc As String
'Set up Proc String to accept the procedure and parameter fields
strSQLProc = "informix.sp_dly_rpt_sls"
' Set up trial parameters to pass
comp = 1
v_co = 1
stor = 962
v_st = 962
from_acct_yr_mon = "12/2004"
from_acct_day = 1
to_acct_yr_mon = "12/2004"
to_acct_day = 31
' Set connection strings
strtmsCnxn = "PROVIDER=MSDASQL;dsn=tms_rdb;uid=apple;pwd=pie;database=tms_rdb;"
'strsdsCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\ta\sales\sds.mdb;uid=admin;pwd=admin"
' Set Cnxn = New ADODB.Connection
Set Cnxntms = New ADODB.Connection
'Set Cnxnsds = New ADODB.Connection
' Create command object
' Set cmdChange = New adodb.Command
Set cmdtmsSQL = New ADODB.Command
'Set cmdsds = New ADODB.Command
' Cnxn.Open strCnxn
Cnxntms.Open strtmsCnxn
'Cnxnsds.Open strsdsCnxn
MsgBox "Connection opened"
'Set Command type and load with procedure name
cmdtmsSQL.CommandType = adCmdStoredProc
cmdtmsSQL.CommandText = strSQLProc
' Set cmdChange.ActiveConnection = Cnxn
Set cmdtmsSQL.ActiveConnection = Cnxntms
'Set cmdsds.ActiveConnection = Cnxnsds
'Set recordsets = New ADODB.Recordset
Set adotmsRS = New ADODB.Recordset
'Set adosdsRS = New ADODB.Recordset
'Create 8 input parameters for the stored procedure to be called
Set prm01 = cmdtmsSQL.CreateParameter("comp", adSmallInt, adParamInput, comp)
Set prm02 = cmdtmsSQL.CreateParameter("v_co", adSmallInt, adParamInput, v_co)
Set prm03 = cmdtmsSQL.CreateParameter("stor", adSmallInt, adParamInput, stor)
Set prm04 = cmdtmsSQL.CreateParameter("v_st", adSmallInt, adParamInput, v_st)
Set prm05 = cmdtmsSQL.CreateParameter("from_acct_yr_mon", adVarChar, adParamInput, from_acct_yr_mon)
' *******The preceeding "Set prm05 =...." causes the Runtime Error '91' message. I used the Vb debugger to isolate to the execution of this statement. Stop at Set prm05 - no error. Continue to >Set prm06 and you get the error. (the line rap in this statement is not in the source)
Set prm06 = cmdtmsSQL.CreateParameter("from_acct_day", adInteger, adParamInput, from_acct_day)
Set prm07 = cmdtmsSQL.CreateParameter("to_acct_yr_mon", adVarChar, adParamInput, to_acct_yr_mon)
Set prm08 = cmdtmsSQL.CreateParameter("to_acct_day", adInteger, adParamInput, to_acct_day)
cmdtmsSQL.Parameters.Append prm01
cmdtmsSQL.Parameters.Append prm02
cmdtmsSQL.Parameters.Append prm03
cmdtmsSQL.Parameters.Append prm04
cmdtmsSQL.Parameters.Append prm05
cmdtmsSQL.Parameters.Append prm06
cmdtmsSQL.Parameters.Append prm07
cmdtmsSQL.Parameters.Append prm08
' ExecuteCommand the procedure and return a complete record set from the stored procedure
ExecuteCommand cmdtmsSQL, adotmsRS
' Print report of new data
' Debug.Print _
' "Data in Titles table after executing the query"
Debug.Print "Records retrieved > " & adotmsRS.RecordCount
Debug.Print "Fields retrieved > " & adotmsRS.Fields.Count
Debug.Print "Stored procedure worked! Hopefully!"
' Clean up
' Cnxn.Close
Cnxntms.Close
' Cnxnsds.Close
Set Cnxntms = Nothing
' Set Cnxnsds = Nothing
Exit Sub
Err_Execute:
' Notify user of any errors that result from
' executing the query
If adotmsRS.ActiveConnection.Errors.Count >= 0 Then
For Each Err In adotmsRS.ActiveConnection.Errors
MsgBox "Error number: " & Err.Number & vbCr & _
Err.Description
Next Err
End If
' Clean up
If Not adotmsRS Is Nothing Then
If adotmsRS.State = adStateOpen Then adotmsRS.Close
End If
Set adotmsRS = Nothing
If Not Cnxntms Is Nothing Then
If Cnxntms.State = adStateOpen Then Cnxntms.Close
End If
Set Cnxntms = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
Public Sub ExecuteCommand(cmdTemp As ADODB.Command, rstTemp As ADODB.Recordset)
Dim Err As Error
' Run the specified Command object and trap for
' errors, checking the Errors collection
On Error GoTo Err_Execute
cmdTemp.Execute
On Error GoTo 0
Exit Sub
Err_Execute:
' Notify user of any errors that result from
' executing the query
If rstTemp.ActiveConnection.Errors.Count > 0 Then
For Each Err In rstTemp.ActiveConnection.Errors
MsgBox "Error number: " & Err.Number & vbCr & _
Err.Description
Next Err
End If
Resume Next
End Sub
Public Sub PrintOutput(rstTemp As ADODB.Recordset)
' Enumerate Recordset
Do While Not rstTemp.EOF
Debug.Print " " & rstTemp!Title & _
", " & rstTemp!Type
rstTemp.MoveNext
Loop
End Sub
'EndExecuteVB
Private Sub Text1_Change()
End Sub
Private Sub txtEndDate_Change()
End Sub
Private Sub txtStartDate_Change()
End Sub
Private Sub txtCorporateName_Change()
End Sub