Connection ADO.NET to Yandex Cloud

Installation

To use Yandex Cloud authentication in your .NET application, install the Ydb.Sdk.Yc.Auth NuGet package:

dotnet add package Ydb.Sdk.Yc.Auth

This package provides the necessary tools for authenticating with Yandex Cloud services.

Authentication

Supported Yandex.Cloud authentication methods:

  • Ydb.Sdk.Yc.ServiceAccountProvider. Service account authentication, sample usage:

    var saProvider = new ServiceAccountProvider(
        saFilePath: file, // Path to file with service account JSON info
        loggerFactory: loggerFactory
    );
    
  • Ydb.Sdk.Yc.MetadataProvider. Metadata service authentication, works inside Yandex Cloud VMs and Cloud Functions. Sample usage:

    var metadataProvider = new MetadataProvider(loggerFactory: loggerFactory);
    

Certificates

The library includes default Yandex Cloud server certificates, which are required for connectivity with dedicated YDB databases:

var certs = Ydb.Sdk.Yc.YcCerts.GetYcServerCertificates();

How to Connect with ADO.NET

To establish a secure connection to YDB using ADO.NET, configure YdbConnectionStringBuilder with the required authentication and TLS settings. Below is a detailed example:

var builder = new YdbConnectionStringBuilder
{
    // More settings ...
    UseTls = true,
    Port = 2135,
    CredentialsProvider = saProvider, // For service account
    ServerCertificates = YcCerts.GetYcServerCertificates() // custom certificates Yandex Cloud
};

Example

ADO.NET connect to Yandex Cloud