Why does SQL Anywhere ignore the @ named parameter?

.net ado.net dapper sqlanywhere

Question

I am using Dapper to query a SQL Anywhere Datasource, and I am getting an error that makes it seem that the "@" prefix for my where clause value is ignored.

 Double balance = qb.Query<Double>("select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = @listid", new { listid = ListID }).Single();

Error:

Column '@listid' not found

I have access to that table and my manual query works fine.

select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = '8000000B-1433635931'

Example:

enter image description here

Accepted Answer

With SQL Anywhere and its .Net data provider (at least Sap.Data.SQLAnywherev4.5), parameters should be prefixed with : instead of @.

This looks to me as being the issue in your case. But I do not know if Dapper is supposed to abstract away such vendor's specific behavior from its users.

So you should try with:

Double balance = qb.Query<Double>(
    "select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = :listid",
    new { listid = ListID }).Single();

Popular Answer

Looks for me that you try to use a variable @listid which is not declared.

If I use DBISQL with SQL Anywhere I would have wrote somthing like this:

BEGIN

DECLARE @list varchar(20);

SET @list = '8000000B-1433635931';

select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = @listid";

END




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why