ODBC query with parameter throws "[HY104] invalid precision value"
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
It's a very simple query with a LIKE operator on an access database:
string sql = "SELECT FROM Users WHERE UserName LIKE ?";
var result = conn.Query<User>(sql, "%ab%"});
Throws exception:
Unhandled exception. System.Data.Odbc.OdbcException (0x80131937): ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value
I also tried different parameter passing ways:
conn.Query<User>(sql, new {UserName = "%ab%"})
var dp = new DynamicParameters();
dp.Add("", "%ab%");
conn.Query<User>(sql, dp);
None of them works.
But using ODBC parameter directly can query as expected:
var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Users WHERE UserName LIKE ?";
cmd.Parameters.Add(new OdbcParameter("", "%ab%"));
var reader = cmd.ExecuteReader();
Am I missing something?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Access query, then compare parameter binding through conn.Query and DynamicParameters with the working CreateCommand and OdbcParameter path. Done means the parameterized Query call handles the LIKE value without the HY104 invalid precision error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100