简体   繁体   中英

SQL Server varchar(MAX) parameter results in “Parameter object is improperly defined”

I have a field in a table that I want to store a potentially long error string. To this end I selected varchar(MAX) as the data type. I have created a stored procedure that is used to enter that data in the table and for the field "ErrorDescription" I used the following parameter definition.

@ErrorDescription as varchar(MAX)

The problem is within the ADO Procedure (within Access 2003) that calls the stored procedure to log the error. I take the error description as a string value and attempt to assign it to the parameter ...

cmd.Parameters("@ErrorDescription").Value = errorDescription

but it fails with the following error.

"Parameter object is improperly defined"

If I change the stored procedure definition to ...

 @ErrorDescription as varchar(255)

Then all works well. How can I define the stored procedure parameter to accept a potentially very long string? Is varchar(MAX) the wrong datatype to use? Thank you.

EDIT I should have mentioned the version of SQL Server I was using. I am using SQL Server 2008.

varchar(MAX) was introduced with SQL Server version 2005. I assume that you are using the 2000 version. If so, then you can wither use varchar(8000) or Text

我猜想Access 2003不知道MAX关键字代表什么,因为它是在SQL 2005中引入的。我不确定是否可以通过使用TEXT数据类型来欺骗Access并让SQL将其正确映射到VARCHAR(MAX)列,但是。

I would first look at definition of column in database to confirm datatype.

SQL_LONGVARCHAR is the server type that is mapped to the Memo field, which I assume to be the Access data type that you want for this data. If that assumption is correct, it looks like you'll need to change the server data type to SQL_LONGVARCHAR (eg create the column as type 'text' instead of 'varchar(max)').

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM