Google Cloud SQL for SQL Server is a fully managed relational database service that hosts Microsoft SQL Server in the cloud. It allows developers to continue using familiar SQL Server tools and existing skills while automating routine database management tasks. The service also integrates seamlessly with other Google Cloud products, such as Google Kubernetes Engine (GKE) and Cloud Functions.

For organizations that rely on Google Cloud infrastructure but want to keep the advantages of SQL Server without maintaining their own database servers, Cloud SQL for SQL Server provides a strong alternative to Azure SQL Database.

This guide explains how to connect .NET applications to SQL Server instances hosted on Google Cloud and perform essential data operations. To ensure a smooth, secure, and reliable connection without complex configuration or additional client libraries, we will use Devart's dotConnect for SQL Server, a high-performance data provider for .NET.

Why dotConnect for SQL Server?

ORM support provided

No client libraries required

Connect to SQL Server directly via TCP/IP without installing SQL Server client software.

Full ADO.NET compliance

Full ADO.NET compliance

Leverage familiar ADO.NET interfaces and components for smooth integration and predictable behavior.

Support for Oracle-specific data types

Secure and stable

Supports encrypted connections and undergoes continuous performance and security testing to meet enterprise standards.

Secure connection ensured

Broad compatibility

Works across all major versions of SQL Server and supports .NET Framework, .NET Core, and .NET 5/6/7+.

Integration with popular IDEs

IDE integration

Features native integration with Visual Studio and complete design-time support.

Priority support provided

Priority support & frequent updates

Enjoy priority support, detailed documentation, and regular updates for continuous improvement.

Download and activate dotConnect for SQL Server

You can start using dotConnect for SQL Server immediately with a 30-day free trial. Choose one of the following installation options:

30-day free trial version

dotnet add package Devart.Data.SqlServer
Install-Package Devart.Data.SqlServer

You can install the driver by using the Windows installer.

After you receive the license key, add it to your connection strings to connect to the data source.

Start using dotConnect for SQL Server in your project today with a free trial

Connect to Google's Cloud SQL for SQL Server with Data Explorer

To connect to SQL Server using the built-in Data Explorer, click Tools and select Connect to Database. Then choose SQL Server as the data source.

Connect to SQL Server in Cloud SQL for SQL Server using Data Explorer

Enter the necessary credentials and click Connect.

Enter the necessary credentials to connect to Cloud SQL for SQL Server

Once connected, you can browse tables, execute queries, and manage data directly within the Data Explorer.

View the Cloud SQL for SQL Server data in the Data Explorer

Connect and retrieve data from the database

Now we can connect our project to Cloud SQL for SQL Server from the .NET application and access our data in the cloud.

Create DatabaseConnection.cs (connection strings)

This class keeps connection details separate for better maintainability.

using Devart.Data.SqlServer;

namespace GoogleSqlTest
{
    public static class DatabaseConnection
    {
        public static SqlConnection CreateConnection()
        {
            string connectionString =
                "Data Source=127.0.0.1;" +
                "User Id=TestUser;" +
                "Password=TestPassword;" +
                "Initial Catalog=TestDb;" +
                "Encrypt=True;" +
                "TrustServerCertificate=True;" +
                "License Key=**********";

            return new SqlConnection(connectionString);       }
    }
}

Connection strings

Property Meaning
Database Default database to be used after connecting
Server or Host Hostname or IP address of the SQL Server
License Key Your license key. This is required only when using .NET Standard compatible assemblies
Password Password for the user ID
Port Port number on which the SQL Server is listening
UserId User ID used to authenticate with SQL Server
Note
For the complete list of supported parameters and advanced configuration options, refer to .NET Connection Strings for SQL Server.

Update the connection string

Replace the placeholders in the connection string with your actual database credentials.

Note
If you own a paid license of dotConnect for SQL Server, include the license key in the connection strings.

Add the code below to the Program.cs file.

using Devart.Data.SqlServer;

partial class Program
{
    static void Main(string[] args)
    {

        try
        {
            using (var connection = GoogleSqlTest.DatabaseConnection.CreateConnection())
            {
                connection.Open();
                Console.WriteLine("Successfully connected to SQL Server!\n");

                using (SqlCommand command = new SqlCommand("SELECT TOP (10) * FROM actor", connection))
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine($"Actor ID: {reader["actor_id"]}, " +
                                          $"Name: {reader["first_name"]} {reader["last_name"]}");
                    }
                }
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine($"Error connecting to database: {ex.Message}");
        }
    }
}

Run the application

Press F5 or select Start from the menu. You will see the data retrieved from the database.

View the data from the Cloud SQL for SQL Server database in the application

Insert new records into a table in Cloud SQL for SQL Server

Let's add a new record to the Actor table using ADO.NET classes.

using System;
using Devart.Data.SqlServer;

partial class Program
{
    static void Main(string[] args)
    {
        var first = args.Length > 0 ? args[0] : "Chris";
        var last = args.Length > 1 ? args[1] : "Pratt";

        try
        {
            using (var connection = GoogleSqlTest.DatabaseConnection.CreateConnection())
            {
                connection.Open();
                Console.WriteLine("Successfully connected to SQL Server!\n");

                string sql =
                    "INSERT INTO actor (first_name, last_name) " +
                    "OUTPUT inserted.actor_id, inserted.first_name, inserted.last_name " +
                    "VALUES (@first, @last);";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add(new SqlParameter("@first", first));
                    command.Parameters.Add(new SqlParameter("@last", last));

                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            Console.WriteLine("Inserted actor:");
                            Console.WriteLine($"Actor ID: {reader["actor_id"]}, " +
                                              $"Name: {reader["first_name"]} {reader["last_name"]}");
                        }
                        else
                        {
                            Console.WriteLine("Insert succeeded but no row was returned.");
                        }
                    }
                }
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine($"Error connecting to database: {ex.Message}");
        }
    }
}

The operation is successful, and we can view the results in the application:

Insert a new record into the database table in Cloud SQL for SQL Server

Update rows in Cloud SQL for SQL Server

Our next task is to update an existing record. We can do it directly from the application in the following way:

using System;
using Devart.Data.SqlServer;

partial class Program
{
    static void Main(string[] args)
    {
        try
        {
            using (var connection = GoogleSqlTest.DatabaseConnection.CreateConnection())
            {
                connection.Open();
                Console.WriteLine("Successfully connected to SQL Server!\n");

                string sql =
                    "UPDATE actor " +
                    "SET first_name = @first, last_name = @last " +
                    "WHERE actor_id = 51;";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add(new SqlParameter("@first", "Denzel"));
                    command.Parameters.Add(new SqlParameter("@last", "Washington"));

                    int rowsAffected = command.ExecuteNonQuery();

                    if (rowsAffected > 0)
                    {
                        Console.WriteLine("Successfully updated actor with ID 51 to Denzel Washington.");
                    }
                    else
                    {
                        Console.WriteLine("No actor found with ID 51, or the name was already Denzel Washington.");
                    }
                }
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine($"Error connecting to database: {ex.Message}");
        }
    }
}

The application shows us the updated data:

Update rows in a database table in Cloud SQL for SQL Server

Delete rows from Cloud SQL for SQL Server

Finally, let us remove the record we previously added. Use the below code:

using System;
using Devart.Data.SqlServer;

partial class Program
{
    static void Main(string[] args)
    {
        try
        {
            using (var connection = GoogleSqlTest.DatabaseConnection.CreateConnection())
            {
                connection.Open();
                Console.WriteLine("Successfully connected to SQL Server!\n");

                string sql = "DELETE FROM actor WHERE actor_id = @actor_id;";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add(new SqlParameter("@actor_id", 51));

                    int rowsAffected = command.ExecuteNonQuery();

                    if (rowsAffected > 0)
                    {
                        Console.WriteLine("Successfully deleted actor with ID 51.");
                    }
                    else
                    {
                        Console.WriteLine("No actor found with ID 51.");
                    }
                }
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine($"Error connecting to database: {ex.Message}");
        }
    }
}

The appilcation shows that the record has been successfully deleted.

Delete records from the database table in Cloud SQL for SQL Server

Conclusion

Cloud SQL for SQL Server is a popular choice for users who want secure, reliable SQL Server performance in the cloud while working within Google's ecosystem. We successfully connected to Cloud SQL for SQL Server using dotConnect for SQL Server and demonstrated how to perform essential data operations with SQL Server data hosted on Google Cloud.

From here, you can build new .NET applications, migrate existing ones to the cloud, and explore more advanced data operations.

FAQ

How do you install and activate dotConnect for SQL Server in a .NET project?
Install dotConnect for SQL Server via the EXE installer or by adding the Devart.Data.SqlServer NuGet package to your project, then obtain your personal activation key from your Devart Customer Portal and include it in the connection string via the License Key parameter for a working connection.
How do you create a connection to SQL Server using dotConnect in C#?
Define a connection string that includes host, user ID, password, database, and the License Key value, then create an SqlConnection instance with this string and call Open() for it inside a try-catch block to test and handle connection errors.
How do you enable encryption for secure SQL Server connections with dotConnect?
Use SQL Server Native Network Encryption by configuring encryption in the sqlnet.ora file on both client and server sides. No special parameters are required in the connection string.
Is it possible to connect to SQL Server using Visual Studio Server Explorer with dotConnect?
Yes, add a new Data Connection in Server Explorer, select dotConnect for SQL Server as the provider, enter your credentials, test the connection, and browse SQL Server data directly in Visual Studio.

Dereck Mushingairi

I'm a technical content writer who loves turning complex topics — think SQL, connectors, and backend chaos–into content that actually makes sense (and maybe even makes you smile). I write for devs, data folks, and curious minds who want less fluff and more clarity. When I'm not wrangling words, you'll find me dancing salsa, or hopping between cities.

Try the 30-day trial of the full product. No limits. No card required. Start free trial