[英]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.
为此,我选择了varchar(MAX)作为数据类型。 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”,我使用了以下参数定义。
@ErrorDescription as varchar(MAX)
The problem is within the ADO Procedure (within Access 2003) that calls the stored procedure to log the error. 问题出在ADO过程(在Access 2003中)内,该过程调用存储过程以记录错误。 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? varchar(MAX)
使用的数据类型错误吗? Thank you. 谢谢。
EDIT I should have mentioned the version of SQL Server I was using. 编辑我应该提到我正在使用的SQL Server版本。 I am using SQL Server 2008.
我正在使用SQL Server 2008。
varchar(MAX)
was introduced with SQL Server version 2005. I assume that you are using the 2000 version. varchar(MAX)
是在SQL Server 2005版中引入的。我假设您使用的是2000版。 If so, then you can wither use varchar(8000)
or Text
如果是这样,则可以使用
varchar(8000)
或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. SQL_LONGVARCHAR是映射到“备注”字段的服务器类型,我假设它是您想要此数据的Access数据类型。 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)').
如果该假设正确,则看起来您需要将服务器数据类型更改为SQL_LONGVARCHAR(例如,将列创建为“文本”类型而不是“ varchar(max)”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.