Giorgi / DuckDB.NET

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

How to property the connection string as java #78

Closed qmatrix123 closed 1 year ago

qmatrix123 commented 1 year ago

Properties ro_prop = new Properties(); ro_prop.setProperty("duckdb.read_only", "true"); Connection conn_ro = DriverManager.getConnection("jdbc:duckdb:/tmp/my_database", ro_prop);

As java, I can pass configuration to connection.How can I do the same thing with the lib.

Thanks.

qmatrix123 commented 1 year ago

I use these code to config the access_mode property, but it can not work.Please show me some hints.

using (var duckDBConnection = new DuckDB.NET.Data.DuckDBConnection(budiler.ConnectionString))
{

    duckDBConnection.Open();

    var command = duckDBConnection.CreateCommand();

    command.CommandText = "set access_mode=READ_ONLY;";
    var executeNonQuery = command.ExecuteNonQuery();

    command.CommandText = "SELECT current_setting('access_mode');";
    var executeScalar = command.ExecuteScalar();

    Thread.Sleep(1000 * 3);

    Console.WriteLine(executeScalar);
}
Giorgi commented 1 year ago

You cannot specify connection properties in the connection string yet but there is an open issue for that: #49

You should be able to achieve it by using Configure Api

Giorgi commented 1 year ago

Your code also works for me with DuckDB 0.6.1:

image