Get connection information for an instance

This snippet shows how to retrieve connection information, including the IP address and instance name, for a specific instance. Use this information to connect a client application to your database.

Code sample

C#

To authenticate to AlloyDB, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

using Google.Cloud.AlloyDb.V1;

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for GetConnectionInfo</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void GetConnectionInfo()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        string parent = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]/instances/[INSTANCE]";
        // Make the request
        ConnectionInfo response = alloyDBAdminClient.GetConnectionInfo(parent);
    }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.