It's been a long time since I did any classic asp work, but was recently asked to pick up a project that someone else had been working on which was a mess.
The site has a SQL Server 2008 database at the back end and I need to add a record and retrieve the auto identity column as an out parameter.
My asp code is shown here...
Call fncOpenData()
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = oConn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_ins_MyRecord"
cmd.Parameters.Refresh
cmd.Parameters.Append cmd.CreateParameter("@MyValue", adVarChar, adParamInput, 10)
cmd.Parameters("@MyValue") = Request.Form("MyValue")
cmd.Execute
and my stored procedure was created with the code here...
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE usp_ins_MyRecord
@MyValue varchar(10)
AS
BEGIN
INSERT INTO [MyRecords]
(
[MyValue]
)
VALUES
(
@MyValue
)
END
GO
Now, when I run my asp page I get the following error...
"Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function usp_ins_MyRecord has too many arguments specified.
/MyPage.asp, line ..."
If I remove the line
cmd.Parameters.Refresh
I get the following error...
"Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function 'usp_ins_MyRecord' expects parameter '@MyValue', which was not supplied.
/MyPage.asp, line ..."
Erm, yes it was?!
If I change my code in any other way to add the parameter, such as
cmd.Parameters.Append cmd.CreateParameter("@MyValue", adVarChar, adParamInput, 10, Request.Form("MyValue")
or
myValue = Request.Form("MyValue")
Set param = cmd.CreateParameter("@MyValue", advarchar, adParamInput, 10)
cmd.Parameters.Append param
param.Value = myValue
I get the same error as before, stating the parameter wasn't specified?
I know the technology is dated and really wish I could use .Net but this is what I have to use, but I'm pulling my hair out here and getting nowhere fast.
Can anyone see what's wrong, or explain why I'm having trouble getting ASP to use SQL Server 2008 stored procs?
Thanks.