I'm wrestling with the correct parameter definition to use when attempting to store a file to a SQL server db using a stored procedure. The sproc needs to save the record and return the key/id to the caller. Sproc parameters look like this:
procedure sp_insert_attachment @attachment_id char(25) OUTPUT, @digital_image varbinary(max), @comments varchar(max),
@file_name varchar(max), @file_size numeric(18,2), @parent_table varchar(50), @parent_id char(25), @import_date datetime,
@add_user char(25), @add_datetime datetime
as
SET @attachment_id = CONVERT(CHAR(25), Substring(Replace(Newid(), '-', ''), 1, 25))
INSERT INTO [i_attachment]
([attachment_id]
,[digital_image]
,[comments]
,[file_name]
,[file_size]
,[parent_table]
,[parent_id]
,[import_date]
,[add_user]
,[add_datetime]
,[status])
VALUES
(@attachment_id,
@digital_image,
@comments,
@file_name,
@file_size,
@parent_table,
@parent_id,
@import_date,
@add_user,
@add_datetime,
'A')
I've gone through several permutations of parameter types. Currently, this is what I have:
set g_rst = Server.CreateObject("ADODB.Command")
g_rst.CommandText = "sp_insert_attachment"
g_rst.ActiveConnection = Mconn
g_rst.NamedParameters = true
g_rst.CommandType = adCmdStoredProc
g_rst.Parameters.Append(g_rst.CreateParameter("@attachment_id", SqlDbType.Char, adParamOutput))
g_rst.Parameters.Append(g_rst.CreateParameter("@digital_image", SqlDbType.VarBinary, adParamInput, objUpload.Form("FILE1").SaveAsBlob ))
g_rst.Parameters.Append(g_rst.CreateParameter("@comments", SqlDbType.VarChar, adParamInput, -1, g_strNarrative))
g_rst.Parameters.Append(g_rst.CreateParameter("@file_name", SqlDbType.VarChar, adParamInput, -1, g_strFileName))
g_rst.Parameters.Append(g_rst.CreateParameter("@file_size", SqlDbType.Decimal, adParamInput, g_dblFileSize))
g_rst.Parameters.Append(g_rst.CreateParameter("@parent_table", SqlDbType.VarChar, adParamInput, 50, "event"))
g_rst.Parameters.Append(g_rst.CreateParameter("@parent_id", SqlDbType.Char, adParamInput, 25, g_strEventID))
g_rst.Parameters.Append(g_rst.CreateParameter("@import_date", SqlDbType.DateTime2, adParamInput, DateTime.Parse(now())))
g_rst.Parameters.Append(g_rst.CreateParameter("@add_user", SqlDbType.Char, adParamInput, 25, session("sec_user_id")))
g_rst.Parameters.Append(g_rst.CreateParameter("@add_datetime", SqlDbType.DateTime2, adParamInput, DateTime.Parse(now())))
g_rst.Execute
g_rst.Close
This is throwing a -2147217900 error. Any help is greatly appreciated.