C#/.NET¶
The ADBC C#/.NET libraries support three different ways of using ADBC:
Native C# drivers for databases like Google BigQuery
Bindings packages that wrap individual drivers such as the Snowflake Go driver
A driver manager for loading ADBC drivers written in other languages at runtime
Here we’ll briefly tour basic features using the driver manager and the PostgreSQL driver.
Installation¶
dotnet add package Apache.Arrow.Adbc
Installing Drivers¶
See Installing Drivers for instructions on installing ADBC drivers for the database you want to connect to. For the example below, you could install dbc and then install the PostgreSQL driver with:
dbc install postgresql
Usings¶
using System.Collections.Generic;
using Apache.Arrow;
using Apache.Arrow.Adbc;
using Apache.Arrow.Adbc.DriverManager;
using Apache.Arrow.Ipc;
Basic Usage¶
using AdbcDriver driver = AdbcDriverManager.FindLoadDriver(
"postgresql",
loadOptions: AdbcLoadFlags.Default);
using AdbcDatabase db = driver.Open(new Dictionary<string, string>
{
["uri"] = "postgresql://localhost:5432/postgres",
});
using AdbcConnection conn = db.Connect(null);
using AdbcStatement stmt = conn.CreateStatement();
stmt.SqlQuery = "SELECT * FROM foo";
QueryResult result = stmt.ExecuteQuery();
using IArrowArrayStream stream = result.Stream!;
while (true)
{
using Apache.Arrow.RecordBatch batch = await stream.ReadNextRecordBatchAsync();
if (batch == null) break;
// process batch
}
Next Steps¶
Explore more C# examples in the adbc-quickstarts repository