H2Sharp 0.1.41-alpha.1

This is a prerelease version of H2Sharp.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package H2Sharp --version 0.1.41-alpha.1
                    
NuGet\Install-Package H2Sharp -Version 0.1.41-alpha.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="H2Sharp" Version="0.1.41-alpha.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="H2Sharp" Version="0.1.41-alpha.1" />
                    
Directory.Packages.props
<PackageReference Include="H2Sharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add H2Sharp --version 0.1.41-alpha.1
                    
#r "nuget: H2Sharp, 0.1.41-alpha.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package H2Sharp@0.1.41-alpha.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=H2Sharp&version=0.1.41-alpha.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=H2Sharp&version=0.1.41-alpha.1&prerelease
                    
Install as a Cake Tool

<p align="center"> <img src="assets/h2sharp-banner-clean.png" alt="H2Sharp — H2 Database engine, ported to C# / .NET" width="100%"> </p>

<p align="center"> <a href="https://github.com/dimzon/h2sharp/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/dimzon/h2sharp/actions/workflows/ci.yml/badge.svg"></a> <img alt=".NET 8 / 10" src="https://img.shields.io/badge/.NET-8.0%20%7C%2010.0-512BD4?logo=dotnet"> <img alt="H2 reference 2.5.x" src="https://img.shields.io/badge/H2%20reference-2.5.x-38bdf8"> <a href="LICENSE-H2.txt"><img alt="License: MPL-2.0 OR EPL-1.0" src="https://img.shields.io/badge/license-MPL--2.0%20OR%20EPL--1.0-blue"></a> <img alt="Status: active port" src="https://img.shields.io/badge/status-active%20port-blue"> <img alt="Coverage: about 94.8% and growing" src="https://img.shields.io/badge/coverage-~94.8%25%20and%20growing-34d399"> </p>

H2Sharp is an embeddable SQL database engine for .NET — a faithful, actively developed port of H2 Database 2.5.x from Java to C#. It exposes a standard ADO.NET provider (System.Data.Common), so ordinary DbConnection/DbCommand code, Dapper and provider-agnostic consumers run against an in-process engine: no server, no separate process. Both in-memory and file-based MVStore databases are supported, and files written here open in the reference Java H2 2.5.259 — and vice versa.

Open connections through H2DataSource. It owns the database and is the only correct way to connect: every connection it hands out shares one engine instance. A directly constructed H2Connection is a self-contained, single-connection database and does not share state — see Quick start.

The port is in active development with roughly 94.8% line coverage and 91.3% branch coverage (Debug union run, 2026-11-18). Where the reference H2 can do something the port cannot yet, the port throws TODOException rather than returning a plausible but wrong answer: a stub that refuses is never a stub that answers.

At a glance

Reference H2 2.5.x, pinned in reference/H2_COMMIT.txt. Never target another version: 1.x and 2.5.x diverge.
Target frameworks net8.0, net10.0 (SDK pinned in global.json)
Public API H2Sharp.Data — H2DataSource / H2DataSourceBuilder (entry point), H2Connection, H2Command, H2Parameter, H2DataReader, H2ProviderFactory, …
Storage in-memory and file-based MVStore; files round-trip with reference Java H2 2.5.259
Status active port · ≈94.8% line coverage / 91.3% branches · CI on Windows + Ubuntu
License MPL-2.0 OR EPL-1.0 (same terms as H2)

Contents

Quick start · Goals · Non-goals · Project status · Related projects · Building and testing · Tools · ADO.NET provider guide · Porting rules · Brand assets · Licensing

Full provider documentation (RU, with examples and gotchas): docs/ADO_NET_GUIDE.md.

Quick start

Plain ADO.NET — no external packages:

using System;
using H2Sharp.Data;

// H2DataSource owns the database. Always connect through it.
using H2DataSource source = new H2DataSourceBuilder("Data Source=quickstart;Storage=Memory").Build();
using H2Connection connection = (H2Connection)source.CreateConnection();
connection.Open();

using var create = connection.CreateCommand();
create.CommandText = "CREATE TABLE T(ID INT, NAME VARCHAR(20))";
create.ExecuteNonQuery();

using var insert = connection.CreateCommand();
insert.CommandText = "INSERT INTO T VALUES ($id, $name)";
var id = insert.CreateParameter();
id.ParameterName = "$id";
id.Value = 1;
insert.Parameters.Add(id);
var name = insert.CreateParameter();
name.ParameterName = "$name";
name.Value = "bolt";
insert.Parameters.Add(name);
insert.ExecuteNonQuery();

using var query = connection.CreateCommand();
query.CommandText = "SELECT NAME FROM T WHERE ID = $id";
var key = query.CreateParameter();
key.ParameterName = "$id";
key.Value = 1;
query.Parameters.Add(key);
Console.WriteLine(query.ExecuteScalar()); // bolt

With Dapper, the same flow is shorter:

using Dapper;
using H2Sharp.Data;

using H2DataSource source = new H2DataSourceBuilder("Data Source=quickstart;Storage=Memory").Build();
using var connection = source.CreateConnection();
connection.Open();
connection.Execute("CREATE TABLE T(ID INT, NAME VARCHAR(20))");
connection.Execute("INSERT INTO T VALUES ($id, $name)", new { id = 1, name = "bolt" });
string name = connection.QuerySingle<string>("SELECT NAME FROM T WHERE ID = $id", new { id = 1 });

For a persistent database, change the connection string — the data source is still the entry point:

using H2DataSource fileSource = new H2DataSourceBuilder("Data Source=./demo-db;Storage=File")
    .Build();
using H2Connection fileConnection = (H2Connection)fileSource.CreateConnection();
fileConnection.Open();
// The resulting MVStore file is readable by the reference Java H2 2.5.259 and vice versa;
// see tests/H2Sharp.Tests/FileDatabaseOracleTests.cs.

Named parameters, arrays, JSON and regex semantics are documented in the ADO.NET provider guide below.

Goals

  • Embedded, in-memory and file-based relational database engine.
  • Public API as a standard ADO.NET provider (System.Data.Common), so it works with Dapper, System.Data.Common consumers and EF Core.
  • MVStore persistence faithful enough that a database file produced by H2Sharp can be opened by the reference Java implementation, and vice versa — this round trip is covered by JavaOracleFact tests (tests/H2Sharp.Tests/FileDatabaseOracleTests.cs).

Non-goals

  • Server/TCP mode and the H2 web console.
  • Full-text search.
  • Encrypted databases.

Project status

The port covers the SQL surface, the ADO.NET provider (Dapper, DbBatch, DbCommandBuilder, GetSchema, typed DbDataReader) and the MVStore file engine, with both in-memory and file-based storage. File databases survive reopening and round-trip with the reference Java H2 2.5.259. The latest Debug union run (2026-11-18) reports 94.83% line coverage (85 616/90 282) and 91.30% branch coverage; per-sprint history is in MIGRATION_STATUS.md, and the measurement setup — in docs/COVERAGE_ANALYSIS.md (an older 2026-11-02 snapshot).

Development is active, and remaining gaps are tracked rather than papered over: where the reference H2 can do something the port cannot yet, the port throws TODOException instead of returning a plausible but wrong answer. A missing feature is unfinished work on the port, not a property of the database.

Current numbers, per-phase status and working notes live in the repository rather than in this README, so they can be updated with the code:

Document What it holds
docs/ROADMAP.md Early phase plan — its status section describes an older snapshot (HEAD 627a7d2); prefer the working notes and tests for the current state
MIGRATION_STATUS.md Working notes, per-sprint status and current coverage (94.83% lines / 91.30% branches, 2026-11-18)
ADO_NET_TESTS.md ADO.NET conformance test suites and their state
docs/ADO_NET_GUIDE.md Full ADO.NET provider guide (RU): API, connection strings, parameters, readers, transactions, batches, extensions, gotchas
docs/PORTING.md How the reference checkout and the port relate
AGENTS.md Rules for porting work in this repository
docs/COVERAGE_ANALYSIS.md Coverage measurement setup; a 2026-11-02 snapshot (85.72% lines)
  • H2Sharp.EntityFrameworkCore — an Entity Framework Core provider for this engine, in a sibling checkout (../h2sharp-efcore, branch h2-provider). It is a fork of the EFCore.PG provider with PostgreSQL's surface replaced by H2's: the type mappings, the migrations SQL generator, the connection and the DDL are H2's, and the SQL it generates is checked against the reference engine on the JVM rather than against this port. Integration status and the engine features it relies on are tracked in its docs/DIVERGENCES.md.

  • H2Sharp.Linq2Db — a linq2db provider for this engine, in a sibling checkout (../h2sharp-linq2db). It is written against linq2db's public API and against the engine's public API, and it speaks H2: the identifiers are always quoted, the types are H2's, the paging is LIMIT/OFFSET, the functions of H2 are offered as H2SharpSpecificExtensions, and the catalogue is read from INFORMATION_SCHEMA the way H2 2.5 keeps it. Integration status and the engine features it relies on are tracked in its docs/DIVERGENCES.md.

Building and testing

dotnet build H2Sharp.sln
dotnet test

CI runs the build and tests on Windows and Ubuntu — see .github/workflows/ci.yml. Coverage is measured in Debug; Release inlining distorts line numbers. The measurement setup is in docs/COVERAGE_ANALYSIS.md.

Tools

The repository also contains small client tools over the engine:

ADO.NET provider guide

This section is a quick reference. For the full guide — architecture, every connection string key, parameter rewriting, value mapping, IH2DataFormat, transactions, DbBatch, DbCommandBuilder, .NET extensions, async limitations and a symptom → cause → fix table — see docs/ADO_NET_GUIDE.md (in Russian, with verified code samples). Every snippet below assumes a connection obtained from an H2DataSource as shown in Quick start.

Named parameters

The ADO.NET provider writes a named parameter as $name:

connection.QuerySingle<int>("SELECT $Id", new { Id = 1 });

Names are case-sensitive ($Id and $id are different parameters), a name used twice is the same parameter, and a name with no supplied value is an error. The rewriter turns $name into H2's indexed $N before the engine parses the statement.

@name is an H2 session variable and :name is ordinary H2 syntax (for example inside JSON_OBJECT); neither is a parameter. This is a breaking change from older H2Sharp versions, which treated @name and :name as named parameters. The EF Core and linq2db providers emit $ placeholders. Dapper 2.1.66 recognizes $ in its parameter filtering and list expansion, so $Id and IN $Ids work.

Arrays with ADO.NET and Dapper

H2 array columns use INTEGER ARRAY, VARCHAR(20) ARRAY, or a bounded type such as INTEGER ARRAY[10]. Array parameters accept CLR arrays, lists, and IEnumerable values; enumerables are consumed once per execution. string and byte[] remain text and binary parameters. Use jagged arrays for nested SQL arrays.

using H2Sharp.Data;
using Dapper;

using H2DataSource source = new H2DataSourceBuilder("Data Source=arrays;Storage=Memory").Build();
using var connection = source.CreateConnection();
connection.Open();
connection.Execute("CREATE TABLE T(ID INT PRIMARY KEY, NUMBERS INTEGER ARRAY)");

var parameters = new Dapper.DynamicParameters();
parameters.Add("id", 1);
parameters.Add("numbers", new List<int> { 10, 20 }, DbType.Object);
connection.Execute("INSERT INTO T VALUES ($id, $numbers)", parameters);
int[] numbers = connection.QuerySingle<int[]>("SELECT NUMBERS FROM T WHERE ID = 1");

The example uses Dapper, System.Data, and System.Collections.Generic. Explicit DbType.Object sends one native array parameter. Dapper's ordinary IN $ids list expansion also works.

DbDataReader.GetValue() returns typed arrays: int[], string[], Guid[], etc. Numeric arrays containing NULL elements return nullable arrays such as int?[]; a NULL column returns DBNull.Value, and an empty array remains empty. GetFieldType() reports the non-nullable element's array type independently of row contents. Use GetFieldValue<int?[]>() for a consistent explicit type across rows. Reading a NULL element into int[] throws InvalidCastException.

For Dapper properties declared as nullable arrays, configure its typed-reader path once:

Dapper.SqlMapper.AddTypeMap(typeof(int?[]), DbType.Object, useGetFieldValue: true);

This also allows nullable arrays to be sent as one parameter from an anonymous parameter object. Without this mapping, Dapper's default materializer directly casts GetValue().

JSON with ADO.NET and Dapper

JSON columns read as UTF-8 byte[] through GetValue() and ExecuteScalar(), with GetFieldType() reporting byte[], as in H2 2.5 JDBC. Passing those bytes back as a parameter preserves the JSON document. SQL NULL reads as DBNull.Value; JSON null is the four-byte document null.

Use GetString(), GetFieldValue<string>(), or GetTextReader() for JSON text. GetBytes(), GetFieldValue<byte[]>(), and GetStream() expose its UTF-8 bytes. For ordinary Dapper string mapping, select CAST(document AS VARCHAR).

Parameters accept UTF-8 byte[], System.Text.Json.JsonDocument, and System.Text.Json.JsonElement as documents. An ordinary string parameter becomes a JSON string value, even when its contents look like an object; this is H2's conversion rule. STJ values are normalized by the engine when the command runs and are not disposed by the provider.

using var document = System.Text.Json.JsonDocument.Parse("{\"a\": 1}");
var parameters = new Dapper.DynamicParameters();
parameters.Add("document", document, System.Data.DbType.Object);
connection.Execute("INSERT INTO J(D) VALUES ($document)", parameters);
byte[] json = connection.QuerySingle<byte[]>("SELECT D FROM J");

With Dapper, pass STJ values explicitly as DbType.Object. A future per-connection choice of JSON representation is tracked in #29.

Regular expressions

REGEXP, ~, ~*, !~, and !~* use .NET regular-expression syntax and System.Text.RegularExpressions. This is a deliberate project decision. SQL operator syntax and precedence follow H2 2.5; patterns are not translated from Java syntax.

~ searches for a match, ~* ignores case, and !~ / !~* negate the match. Inline options such as (?m), (?s), and (?x) are supported. NULL operands produce NULL; an invalid pattern raises H2 error 22025.

SELECT 'abc' ~ '^a', 'ABC' ~* '^a';
SELECT ID FROM TOPICS WHERE TITLE ~* '(?m)^release' ORDER BY ID;

Porting rules

This is a port, not a reimplementation. The reference is H2 2.5 in reference/h2, pinned by reference/H2_COMMIT.txt; when the reference and the port disagree, the reference is right and the difference is work to do. New classes, members or data structures with no counterpart in org.h2 are not introduced; where the platform prevents a literal port, a TODOException names exactly what is missing instead of inventing a substitute.

Before contributing, read the house rules and the accepted .NET-only boundary:

Brand assets

Vector-first assets for READMEs, docs and package icons live in assets/:

File Use
h2sharp-banner-clean.png / .svg Dark hero banner (no volatile counters)
h2sharp-banner-light-clean.png / .svg Light hero banner
h2sharp-icon-512.png Square package / app icon
h2sharp-logo.svg / h2sharp-logo-dark.svg Wordmark for light / dark backgrounds
h2sharp-mark.svg Transparent cylinder + # mark, no tile or frame

The mark is a database cylinder (the H2 identity) with a # hash (Sharp / C#) drawn inside it, with a contour around each line and a light gradient within. The banner and icon shipped in the NuGet package are listed in src/H2Sharp/H2Sharp.csproj.

Licensing

H2 is dual-licensed under the Mozilla Public License 2.0 and the Eclipse Public License 1.0. H2Sharp is a derivative work and is offered under the same terms; see LICENSE-H2.txt, NOTICE.md and docs/PORTING.md.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on H2Sharp:

Package Downloads
H2Sharp.CsvTools

Optional CSVREAD and CSVWRITE functions for H2Sharp, backed by CsvHelper.

H2Sharp.Crypto

Optional ENCRYPT and DECRYPT functions for H2Sharp.

H2Sharp.JavaLegacy

Optional Java-compatibility helpers for H2Sharp.

H2Sharp.Hashes

Optional SHA-224 and SHA3-224 providers for H2Sharp.

H2Sharp.Extensions

Optional user-defined aggregates and examples for H2Sharp.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.43-alpha.1 0 11/23/2026
0.1.42-alpha.1 0 11/23/2026
0.1.41-alpha.1 0 11/23/2026