forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
19 lines (15 loc) · 826 Bytes
/
Program.cs
File metadata and controls
19 lines (15 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using Npgsql;
var connectionString = Environment.GetEnvironmentVariable("NPGSQL_TEST_DB")
?? "Server=localhost;Username=npgsql_tests;Password=npgsql_tests;Database=npgsql_tests;Timeout=0;Command Timeout=0";
var dataSourceBuilder = new NpgsqlSlimDataSourceBuilder(connectionString);
await using var dataSource = dataSourceBuilder.Build();
await using var conn = dataSource.CreateConnection();
await conn.OpenAsync();
await using var cmd = new NpgsqlCommand("SELECT 'Hello World'", conn);
await using var reader = await cmd.ExecuteReaderAsync();
if (!await reader.ReadAsync())
throw new Exception("Got nothing from the database");
var value = reader.GetFieldValue<string>(0);
if (value != "Hello World")
throw new Exception($"Got {value} instead of the expected 'Hello World'");