Skip to content
Explore

Connect Your Application

.NET
  • 1. Choose Scenario
  • 2. Get Ready
  • 3. Run CrateDB
  • 4. Import Data
  • 5. Explore Queries
  • 6. More Queries
  • 7. Connect
  • 8. Next Steps

Basic CrateDB connectivity

CrateDB can use any PostgreSQL-compatible .NET driver. An example connection string using Npgsql is:

Host=<host>;Port=5432;Database=crate;Username=<user>>;Password=<password>>SSL Mode=<sslmode>

Sample .NET application

sample_application

See a .NET sample application on GitHub →

This is a C#/.NET load generator that connects to a CrateDB cluster over the PostgreSQL wire protocol and runs a configurable mix of queries against German climate and region data. It assumes you have already loaded the data in the "Import Data" step.

The single application class is Program.cs.

The Program.cs class

Here is what the class does:

  1. Opens a Npgsql connection to a CrateDB cluster.
  2. Prints the cluster name (SELECT name FROM sys.cluster) as a connectivity smoke test.
  3. Pre-loads reference data from the database (only for query types that will be run):
    • WKT queries: loads every distinct geo_location and timestamp from demo.climate_data.
    • REGION queries: loads every region_name from demo.german_regions.
  4. Runs a workload of queries at a configurable rate, choosing from three query types:
    • WKT — geo-proximity query: finds min/max temperature within 1 metre of a random point at a random timestamp.
    • REGION — three-table join: finds the latest temperature readings for every sensor location inside a named German region, converting Kelvin to Celsius.
    • FTS — full-text search: searches the economics column of demo.german_regions using CrateDB's MATCH predicate and returns the top 3 results by relevance score.
  5. Records the round-trip latency of each query in an HdrHistogram and prints percentile summaries when the run finishes.