Expert1.CloudSqlProxy 2.0.8

dotnet add package Expert1.CloudSqlProxy --version 2.0.8
                    
NuGet\Install-Package Expert1.CloudSqlProxy -Version 2.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Expert1.CloudSqlProxy" Version="2.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Expert1.CloudSqlProxy" Version="2.0.8" />
                    
Directory.Packages.props
<PackageReference Include="Expert1.CloudSqlProxy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Expert1.CloudSqlProxy --version 2.0.8
                    
#r "nuget: Expert1.CloudSqlProxy, 2.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Expert1.CloudSqlProxy@2.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Expert1.CloudSqlProxy&version=2.0.8
                    
Install as a Cake Addin
#tool nuget:?package=Expert1.CloudSqlProxy&version=2.0.8
                    
Install as a Cake Tool

Cloud SQL Proxy

This project provides a .NET Standard library for creating and managing a secure connection to Google Cloud SQL instances using a local proxy. The proxy establishes an SSL/TLS connection to the Cloud SQL instance, allowing local applications to communicate with the database securely.

Features

  • Secure connection to Google Cloud SQL instances
  • Automatic SSL/TLS certificate management
  • Supports multiple concurrent connections
  • Handles periodic certificate refresh

Prerequisites

  • .NET Standard 2.0 or later
  • Google Cloud SDK
  • Google Cloud SQL instance

Installation

To install the library, add it to your project via NuGet Package Manager:

PM> Install-Package Expert1.CloudSqlProxy

Usage

Authentication

The proxy supports two methods of authentication:

  1. Credential File: Path to the Google credentials JSON file.
  2. JSON String: Google credentials JSON file content as a string.

Creating a Proxy Instance

To create and start a proxy instance, use the ProxyInstance.StartProxyAsync method. You can provide the authentication method, instance connection string, and credentials.

using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        string instance = "your-project:your-region:your-instance-id";
        string credentialsPath = "path/to/your/credentials.json";
        
        try
        {
            var proxyInstance = await ProxyInstance.StartProxyAsync(
                AuthenticationMethod.CredentialFile, 
                instance, 
                credentialsPath
            );

            Console.WriteLine($"Proxy started. Connect to your database using DataSource: {proxyInstance.DataSource}");
            
            // Use proxyInstance.DataSource to connect to your database

            // When done, dispose the instance to stop the proxy
            proxyInstance.Dispose();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Failed to start proxy: {ex.Message}");
        }
    }
}

Connecting to the Database

Once the proxy is started, you can connect to your Cloud SQL database using the DataSource property of the ProxyInstance. This property provides the 127.0.0.1:<port> string, which can be used in your database connection string.

For example, to connect to a SQL Server instance:

string connectionString = $"Server={proxyInstance.DataSource};Database=your-database;User Id=your-username;Password=your-password;";
using (var connection = new SqlConnection(connectionString))
{
    connection.Open();
    // Perform database operations
}

Stopping the Proxy

To stop the proxy, you can call the Stop method or dispose of the ProxyInstance:


proxyInstance.Stop(); // Stops the proxy

// Or, simply dispose the instance
proxyInstance.Dispose();

Stopping All Proxies

To stop all running proxies, use the InstanceManager.StopAllInstances method:

InstanceManager.StopAllInstances();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.8 224 2/5/2026
2.0.7 321 4/24/2025
2.0.6 241 4/10/2025
2.0.5 172 2/26/2025
2.0.4 178 2/26/2025
2.0.3 175 2/25/2025
2.0.2 172 2/25/2025
2.0.1 186 2/24/2025
2.0.0 193 2/24/2025