简体   繁体   English

SQL Server varchar(MAX)参数导致“参数对象定义不正确”

[英]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.

相关问题 sql server存储过程使用varchar max作为参数 - sql server stored procedure use varchar max as parameter 参数对象定义不正确错误,参数定义似乎正确 - Parameter object improperly defined Error, Parameter definitions seem to be correct 具有varchar参数的SQL Server存储过程返回错误结果 - SQL Server Stored Procedure with varchar parameter returns wrong results 运行时错误“ 3708”:参数对象定义不正确。 提供的信息不一致或不完整 - Run-time error '3708': Parameter Object is improperly defined. Inconsistent or incomplete information was provided Delphi:“参数对象定义不正确。 提供了不一致或不完整的信息。” - Delphi: “Parameter object is improperly defined. Inconsistent or incomplete information was provided.” 未定义SQL Server Reporting Services报表参数 - SQL Server Reporting Services report parameter is not defined 带有固定参数的 SQL Server 用户定义函数 - SQL Server user defined function with fixed parameter SQL Server:用户定义的函数参数 - SQL Server: user defined function parameter SQL Server存储过程不适用于varchar第二个参数 - SQL Server stored procedure not work with varchar second parameter SQL Server varchar(max) 和 varchar 不兼容 - SQL Server varchar(max) and varchar incompatible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM