Skip to content

Commit 40cc2b1

Browse files
updates examples
1 parent be4880c commit 40cc2b1

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

examples/EntityFrameworkCore.Ydb.Samples/AddEntity.Sample/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Section_1.HR;
1+
using Section_1.HR;
42

53
InsertDepartments();
64
SelectDepartments();

examples/Ydb.Sdk.AdoNet.Dapper.QuickStart/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// See https://aka.ms/new-console-template for more information
2-
31
using Dapper;
42
using Ydb.Sdk.Ado;
53

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using System.Diagnostics;
1+
using System.Diagnostics;
42
using Microsoft.Extensions.Configuration;
53
using Microsoft.Extensions.Logging;
64
using Ydb.Sdk.Ado;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# YDB Sdk ADO.NET for Serverless Containers in Yandex Cloud
2+
3+
Sample application uses the YDB SDK for ADO.NET and can be deployed
4+
to [Yandex Cloud Serverless Containers](https://yandex.cloud/en/docs/serverless-containers/).
5+
6+
## Getting started
7+
8+
1. **Setup
9+
** [Yandex Container Registry](https://yandex.cloud/en/docs/container-registry/operations/registry/registry-create).
10+
2. **Build and Push Docker Image**
11+
```bash
12+
docker build . -t cr.yandex/<container-registry-id>/ado-net-app:latest
13+
docker push cr.yandex/<container-registry-id>/ado-net-app:latest
14+
```
15+
Replace <container-registry-id> with your actual Container Registry ID.
16+
3. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
17+
the Container Registry, grant the following roles to your Service Account:
18+
19+
- `ydb.editor` — access to YDB,
20+
- `container-registry.images.puller` — permission to pull images from Container Registry.
21+
22+
4. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
23+
the [official guide](https://yandex.cloud/en/docs/serverless-containers/quickstart/container#create-revision).
24+
Specify your image and the necessary environment variables and secrets.
25+
5. **Running the Yandex Serverless Container**.
26+
After the new revision has been rolled out, you can use your container (e.g., for a health check) by executing the following command:
27+
```bash
28+
curl --header "Authorization: Bearer $(yc iam create-token)" https://<serverless-container-host>/
29+
```
30+
Replace <serverless-container-host> with your actual serverless container host.
31+
32+
## ⚠️ Important Note: YdbDataSource and Connection Handling
33+
34+
When using the YDB SDK in a serverless container, it is always necessary to create a new YdbDataSource for each request
35+
or function invocation.
36+
37+
This is because the network connectivity between a serverless container and external resources, such as YDB, can be
38+
interrupted or reset during execution. If you cache or reuse existing connections, you may experience failures due to
39+
stale or invalid connections.
40+
41+
Best practice:
42+
43+
_Create a fresh data source (or Driver for Topic API) for every request or function invocation in order to ensure
44+
reliability in the serverless environment._

examples/Ydb.Sdk.QueryService.QuickStart/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ internal class CmdOptions
2020
public bool FallbackAnonymous { get; set; } = false;
2121
}
2222

23-
// See https://aka.ms/new-console-template for more information
24-
2523
internal static class Program
2624
{
2725
private static ServiceProvider GetServiceProvider() =>

0 commit comments

Comments
 (0)