Skip to content

Issue with handling '?' character in SQL strings when using SQL Server #1914

@eatmeatHJ

Description

@eatmeatHJ

I've encountered an issue when using Dapper with SQL Server. In my SQL queries, I sometimes include '?' characters inside the string values, as a part of the string itself, not as a parameter placeholder. For example, a query might look like this:

string sql = @"INSERT INTO test_table2 ([name0],[name1],[name2]) VALUES ('?a?', '3.?a?', @name)";
var dp = new Dapper.DynamicParameters();
dp.Add("name", "qq");
conn.Execute(sql, dp);

In this example, '?a?' and '3.?a?' are string values to be inserted into the table, and @name is the only actual parameter in the query.

However, when I execute such a query with Dapper, it throws an exception with the message: "When passing parameters by position, each parameter can only be referenced once."

Is there any way to configure Dapper to correctly handle the '?' characters in SQL strings when using SQL Server?

Any help would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions