DeriveParameters 方法中的参数异常

发布于 2024-09-10 10:26:30 字数 533 浏览 4 评论 0原文

Dim id as integer = 1
Dim command as sqlcommand
Dim reader as idatareader

command = db.GetSqlStringCommand("select id, image, caption from profile where id = @id and image IS NOT NULL Order By NEWID()")
db.AddInParameter(command, "@id", DbType.Int32, id)
reader = db.ExecuteReader(Command)

代码抛出了一个我以前从未见过的错误......

SqlCommand.DeriveParameters 失败,因为 SqlCommand.CommandText 属性值是无效的多部分名称“/port:4544 /path:"C:\sitepath" /vpath:"/sitepath"",引号使用不正确。

我该如何修复该错误。

Dim id as integer = 1
Dim command as sqlcommand
Dim reader as idatareader

command = db.GetSqlStringCommand("select id, image, caption from profile where id = @id and image IS NOT NULL Order By NEWID()")
db.AddInParameter(command, "@id", DbType.Int32, id)
reader = db.ExecuteReader(Command)

The code is throwing an error I've never seen before....

SqlCommand.DeriveParameters failed because the SqlCommand.CommandText property value is an invalid multipart name "/port:4544 /path:"C:\sitepath" /vpath:"/sitepath"", incorrect usage of quotes.

How do I fix that error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不再让梦枯萎 2024-09-17 10:26:30

看起来该代码的失败程度比您发布的代码更深。当我没有正确定义数据库的路径时,我在 SQLServer Management Studio 中收到了类似的错误。
您如何设置对象“db”?

你的连接字符串是什么? (没有密码!:-))

该错误显然与引号位置方面格式错误的字符串有关。您是否知道 entlib 在哪里构造该字符串以及它的某些部分(例如“C:\sitepath”)如何用引号出现而不是作为字符串文字附加?

我想知道某个地方是否有一个诸如

Dim sRootPath As String = """C:\sitepath"""

.. 之类的声明,这会导致引号被插入到构造的字符串中。

It looks like the code is failing at a deeper level than the code you have posted. I have received a similar error from within SQLServer Management Studio when I have not correctly defined the path to my DB.
How are you setting up the object 'db'?

What is your connection string? (Without password! :-))

The error is obviously related the badly formed string in terms of the quote positions. Do you know where entlib is constructing this string and how parts of it such as "C:\sitepath" are appearing with quotes as opposed to being appended as string literals?

I wonder if somewhere there is a declaration such as

Dim sRootPath As String = """C:\sitepath"""

..which is leading to the quotes being inserted into the constructed string.

陌伤浅笑 2024-09-17 10:26:30

我从未见过此错误,但也许此链接有帮助: http://entlib. codeplex.com/Thread/View.aspx?ThreadId=60513

“这是什么版本的 entlib?4.1 中没有接受 sql 语句的 ExecuteReader 重载,有一个接受字符串,但它应该是存储的过程名称。可能您正在使用此重载,但我不确定,因为如果我传递 sql 语句,我会收到不同的错误”

I never saw this error, but perhaps this link helps: http://entlib.codeplex.com/Thread/View.aspx?ThreadId=60513

"What version of entlib is this? There's no overload in 4.1 for ExecuteReader that accepts an sql statement, there is one accepting a string but it should be the stored procedure name. Probably you are using this overload but I'm not sure since I'm getting a different error if I pass an sql statement"

眼眸里的那抹悲凉 2024-09-17 10:26:30

我不知道这个错误,但 NEWID() 的顺序让我有点困扰。使用 newid() SQLServer 为数据集中的每一行调用 newid() 函数。

I don't know about the error but the order by NEWID() bothers me a little. With newid() SQLServer calls the newid() function for each row in your dataset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文