views:

45

answers:

3
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.

Please can you tell me how to go about fixing this error?

Thanks a lot!

A: 

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"

Tim Schmelter
Thanks, I'm using v 5 and using commandname = db.getsqlstringcommand then using this with db.executereader(commandname) works ok in all my other code. The thread from codeplex is not resolved so wasnt greatly helpful.
Phil
A: 

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.

El Ronnoco
enterprise library data access application block is providing the db, connection string being used is the default and works with many many other queries throughout the site. If I replace the params with integer values and run the query in SQLSMS it returns the expected results. Thanks
Phil
A: 

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.

Sjuul Janssen
on removing the order by newid() the error is still the same. Thanks
Phil