To reproduce this error, create a Microsoft Visual Basic (VB) or Active Server Pages (ASP) application and use the ADO code below to connect to SQL Server 7.0 and run the SalesByCategory stored procedure in the Northwind sample database.
The SalesByCategory stored procedure has 2 parameters defined: @CategoryName and @OrdYear. The @OrdYear paramet has a default value of '1998'.
If the .Prepared = True is removed, this code works correctly and does not return an error. If this code is used with SQL Server 2000, the code works correctly due to a new feature which defers the prepare of calls until execution.
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim cn As New ADODB.Connection
cn.Provider = "SQLOLEDB"
cn.ConnectionString = "server=MySQL70;database=Northwind;uid=sa;pwd=;"
cn.Open
With cmd
Set .ActiveConnection = cn
.CommandText = "SalesByCategory"
.CommandType = adCmdStoredProc
.Prepared = True
End With
cmd.Parameters.Refresh
cmd.Parameters("@CategoryName").Value = "Beverages"
Set rs = cmd.Execute
rs.Close
cn.Close