Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
440 stars 70 forks source link

System.AccessViolationException when I run a parameterized query #212

Closed neilfromcork closed 2 months ago

neilfromcork commented 2 months ago

I'm getting the following error when I run a parameterized query:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Code is:

using (DuckDBConnection conn = new DuckDBConnection(connectionString))
                {
                    if (!conn.State.Equals(ConnectionState.Open)) conn.Open();
                    string sql = "SELECT * FROM td_catalog_source where ctl_id=$ctlid;";

                    using DuckDBCommand command = conn.CreateCommand();
                    command.CommandText = sql;

                    command.Parameters.Add(new DuckDBParameter("ctlid", 2));

                    using var result=command.ExecuteReader();
}

Using .Net 8.0, DuckDB.NET.Data.Full 1.0.2, DuckDB.NET.Bindings.Full 1.0.2

Giorgi commented 2 months ago

Does this happen when you are debugging the code? Are you using Rider?

neilfromcork commented 2 months ago

Yes, while debugging. And yes, I'm using Rider.

neilfromcork commented 2 months ago

..works fine when using positional parameters

Giorgi commented 2 months ago

Check this for a workaround: https://github.com/Giorgi/DuckDB.NET?tab=readme-ov-file#known-issues