A simple, practical solution to import and synchronize KBO/BCE/CBE data to your own database (e.g., SQL Server, Postgres, Sqlite, Oracle, ...). It provides clear source abstractions and replaceable storage backends. The acronym CBE stand for "Crossroads Bank for Enterprises in Belgium", and is also known as:
- Dutch: Kruispuntbank van Ondernemingen
- French: Banque-Carrefour des Entreprises
- German: Zentrale Datenbank der Unternehmen
CBE data is provided by the Belgian Governement and is publicly available: https://economie.fgov.be/
1️⃣ Pull data from the official sources of the Belgian Governement.
2️⃣ Maybe cache the files somewhere, using some storage available.
3️⃣ Store the actual data in a database/storage of your liking
4️⃣ Use it in your code as a repository, EF Core DbSet, or service
This section shows a simplified, but concrete example of how the package can be used to create a simple that —ultimately— allows you to search CBE data locally. We have other examples in the samples directory that may give more inspiration. A quick overview:
- Search with EF Core and Sqlite.
- User-friendly web interface, using Dapper and Postgres.
- Generate SQL statements to create configurable tables (DDL)
Back to the concrete example of we can create a simple console app that allows you to search CBE data locally:
Create an account on the official CBE website. With username/password you can download the public open data. 1️⃣
After installing the packages,
dotnet add package Vivarni.CBE
dotnet add package Vivarni.CBE.SqlServer # if you're using SQL Server
dotnet add package Vivarni.CBE.Postgres # if you're using Postgres
dotnet add package Vivarni.CBE.Sqlite # if you're using Sqlite
dotnet add package Vivarni.CBE.Oracle # if you're using Oracleadd your configuration to your IServiceCollection. Adjust connection string, schema, and source for your environment. You can then
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using Vivarni.CBE;
using Vivarni.CBE.Sqlite;
// Configure Vivarni.CBE with the desired source or data store.
// You can easily create your own data store for more control!
var connectionString = "Data Source=c:/kbo.db";
var services = new ServiceCollection()
.AddVivarniCBE(s => s
.WithFtps("cbe-username", "MySecret") 1️⃣
.WithCache("c:/temp/") 2️⃣
.WithSqliteDatabase(connectionString) 3️⃣
);Then run a sync for the first time to trigger an import of your data. The method can be called anytime and will attempt to update to the latest version of CBE data. It will use partial updates when possible and use . The CBE publishes partial update files on a daily basis.ICbeSynchronisationStateRegistry to keep track of the synchronisation state
var provider = services.BuildServiceProvider();
var cbeService = provider.GetRequiredService<ICbeService>();
await cbeService.SyncAsync();using Dapper;
using var connection = new SqliteConnection(connectionString);
await connection.OpenAsync();
var companies = await connection.QueryAsync<(string Vat, string Name)>(
"SELECT vat_number AS Vat, name AS Name FROM cbe_companies WHERE name LIKE @q",
new { q = "%TECH%" }
);
foreach (var row in companies)
{
Console.WriteLine($"{row.Vat} - {row.Name}");
}This project is licensed under the MIT License. Feel free to use it in your projects.