Showing posts with label exceptionquotduplicated. Show all posts
Showing posts with label exceptionquotduplicated. Show all posts

Tuesday, March 6, 2012

"Duplicated parameter names are not allowed" exception in SQL Server Everywhere

I'm using SQL Server Everywhere CTP with ADO.NET and C# 2.0 and getting following exception:
"Duplicated parameter names are not allowed. [ Parameter name = @.NODE_ID ]"
for the query:

SELECT CHANGE_TYPE,CHANGED,VTRANS,LINK_PARTITION_ID,LINK_ID, SOURCE_PARTITION_ID,SOURCE_NODE_ID,TARGET_PARTITION_ID,TARGET_NODE_ID,TYPE,LOCAL_CHANGE_TIME,ATTR FROM VP8657b26964d4c595a7430761c222f3b3_REL WHERE (((TARGET_NODE_ID=@.NODE_ID AND REL_BASE_TYPE=2)) AND LOCAL_CHANGE_TIME > @.LOCAL_CHANGE_TIME ) OR ((SOURCE_NODE_ID=@.NODE_ID AND REL_BASE_TYPE=2)) ORDER BY LOCAL_CHANGE_TIME DESC

Without underlined frament, query runs fine

IDbCommand.Parameters shows that there are exactly 2 parameters with different names: @.LOCAL_CHANGE_TIME and @.NODE_ID

Exception stack trace is:
System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan() + 0xd5 bytes
System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(System.Data.CommandBehavior behavior = Default, string method = "ExecuteReader", System.Data.SqlServerCe.ResultSetOptions options = None) + 0x145 bytes
System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(System.Data.CommandBehavior behavior = Default) + 0x2d bytes
System.Data.SqlServerCe.dll!System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(System.Data.CommandBehavior behavior = Default) + 0x1e bytes
System.Data.dll!System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() + 0xa bytes

So, what this exception might mean? does it mean that a parameter might not be used multiple times in a query?

alex777 wrote:

So, what this exception might mean? does it mean that a parameter might not be used multiple times in a query?

Unfortunately, that's precisely what it means. If you watch (with SQL Profiler, for example) how a query is run when you submit it with ADO, you'll see that it's fluffed and rumpled just a little bit -- in order to make parameters work. That fluff-and-rumple mechanism can't deal with the same parameter name being bound again.

You can rewrite your query to be a batch that assigns @.NODE_ID to a variable, then reference the variable in the query. Or, you can create @.NODE_ID1 and @.NODE_ID2, and spread those guys around in the query -- then bind the same variable in the client code to the two different values (that is, add two parameters, each with the same value as the other).

|||Thanks for your reply,

Is it an issue only with SQL Mobile (aka Everywhere) or this will also

be present in SQL Express and Full-Featured SQL Server or even in any

ADO.NET provider?

> You can rewrite your query to be a batch that assigns @.NODE_ID to a variable, then reference the variable in the query.

SQL Mobile seems not to support batch queries (maybe executing multiply commands within the same connection will work, but it's a pretty mess. )

Anyway, I'm going just to substitue this parameter manually:
com.CommandText = com.CommandText.Replace("@.NODE_ID", "'"+guid.ToString()+"'");