Connect to Cloud SQL for SQL Server from Compute Engine

Learn how to deploy a sample app on your Linux or Windows based Compute Engine VM instance connected to a SQL Server instance by using the Google Cloud console and a client application.

Assuming that you complete all the steps in a timely manner, the resources created in this quickstart typically cost less than one dollar (USD).

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. Verify that you have the permissions required to complete this guide.
  7. Enable the Cloud APIs necessary to run a Cloud SQL sample app on a Compute Engine VM instance.

    Console

    Click the Enable APIs button to enable the API required for this quickstart.

    Enable APIs

    This enables the following API:

    • Cloud SQL Admin API

    gcloud

    Install the gcloud CLI which provides command-line access to your Google Cloud resources. The gcloud CLI is used to run the gcloud CLI commands presented throughout this quickstart. All the commands are formatted to be run in a terminal or a Powershell window.

    Run the following gcloud command:

    gcloud services enable sqladmin.googleapis.com

    This command enables the following API:

    • Cloud SQL Admin API

Required roles

To get the permissions that you need to complete this quickstart, ask your administrator to grant you the following IAM roles:

For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Set up Cloud SQL

Create a Cloud SQL instance

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Delete Cloud SQL instance

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Select the quickstart-instance instance to open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. In the Delete instance dialog box, type quickstart-instance, and then click Delete to delete the instance.

Delete Compute Engine VM instance

  1. In the Google Cloud console, go to the VM instances page.

    Go to VM instances

  2. Select the quickstart-vm-instance instance to open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. Click Delete to delete the instance.

Optional cleanup steps

If you're not using the Cloud SQL client role that you assigned to the Compute Engine default service account, you can remove it.

  1. In the Google Cloud console, go to the Service accounts page.

    Go to IAM

  2. Click the edit icon (which looks like a pencil) for the IAM account named Compute Engine default service account.
  3. Delete the Cloud SQL client role.
  4. Click Save.

If you're not using the API that was enabled as part of this quickstart, you can disable it.

  1. In the Google Cloud console, go to the APIs page.

    Go to APIs

  2. Select any API that you would like to disable and then click the Disable API button.

What's next

Based on your needs, you can learn more about creating Cloud SQL instances.

You also can learn about creating SQL Server users and databases for your Cloud SQL instance.

For more information about pricing, see Cloud SQL for SQL Server pricing.

Learn more about:

Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications: