Giorgi / DuckDB.NET

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

Sqlite_scanner.duckdb_extension #208

Closed bigboybamo closed 1 month ago

bigboybamo commented 1 month ago

I am trying to read from a particular sqlite db but i get the error

DuckDB.NET.Data.DuckDBException
  HResult=0x00000001
  Message=DuckDBOpen failed: IO Error: Extension "C:\Users\user1\.duckdb\extensions\v1.0.0\windows_amd64\sqlite_scanner.duckdb_extension" not found.
Extension "sqlite" is an existing extension.

Install it first using "INSTALL sqlite".
  Source=DuckDB.NET.Data
  StackTrace:
   at DuckDB.NET.Data.Internal.ConnectionManager.GetConnectionReference(DuckDBConnectionString connectionString)
   at DuckDB.NET.Data.DuckDBConnection.Open()
   at Program.<Main>$(String[] args) in C:\Users\user1\source\repos\DuckDBNET\DuckDBNET\Program.cs:line 5

This is my code.

using DuckDB.NET.Data;

using var duckDBConnection = new DuckDBConnection("Data Source=\\sqlite-sakila-db\\sakila.db");
duckDBConnection.Open();

using var command = duckDBConnection.CreateCommand();
command.CommandText = "Select count(*) from actors";
var count = command.ExecuteScalar();
Console.WriteLine(count);

when i run INSTALL sqlite in the command line, I get asked to Enter the absolute path where the nvm-windows zip file is extracted/copied to which I do, and then I get SUCCESS: Specified value was saved.

But I am still running into that error.

Giorgi commented 1 month ago

Does the extension actually exist on the disk? Does it work if you query the db from cli?

bigboybamo commented 1 month ago

@Giorgi Yes it does, and I can query the db from the CLI

I was able to solve this by just adding the DuckDB executable to my project directory.

image

Not sure why, but it worked

Giorgi commented 1 month ago

Can you try again and see if it works now without the executable?

bigboybamo commented 1 month ago

@Giorgi Ah Okay it worked without the executable as well.

Giorgi commented 1 month ago

It looks like the C API does not automatically download the SQLite extension. When you tried it from the cli the extension got downloaded and my library started working.

I have opened an issue in the DuckDB repo to track this: https://github.com/duckdb/duckdb/issues/13363

Closing this one as there isn't much I can do.