Haipeng Su
Haipeng Su

Reputation: 2551

Use Google Cloud API in c#

I having been trying to query databases from Google Cloud SQL in c#. However, I can't get it working.

I followed the Google Reference pages https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/databases/get and tried to do a simple thing such as get the list of databases first.

and in my .csproj file, I have imported several apis.

 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Google.Apis.Auth"/>
     <PackageReference Include="Google.Apis.SQLAdmin.v1beta4"/>
     <PackageReference Include="Google.Apis"/>
     <PackageReference Include='Google.Cloud.Iam.V1' version="1.0.0-beta12" />
     <PackageReference Include="Google.Apis.Core" version="1.28.0" />
   </ItemGroup>
</Project>

Also, I referred to the Github repo and find examples using BigQuery, PubSub and so on but no Cloud SQL. https://github.com/GoogleCloudPlatform/dotnet-docs-samples

Can someone give some advice or point me to the right direction?

Thank you so much.

Upvotes: 1

Views: 1120

Answers (2)

Jeffrey Rennie
Jeffrey Rennie

Reputation: 3443

David is right. Here are some samples that show you how to connect to an SQL database from C#:

dotnet core https://cloud.google.com/appengine/docs/flexible/dotnet/using-cloud-sql

dotnet 4.x https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql

Upvotes: 0

David
David

Reputation: 9731

The APIs you have imported are needed if you want to create or modify Cloud SQL instances from your code, however you don't need them to query an instance.

If your goal is to query an instance you have created with the cloud console or gcloud command, then you should connect to it like any other MySQL database. Documentation for the MySQL Connector/Net is here, and there's also a SO question about it. You will also need to authorize the IP address that you are connecting from.

Upvotes: 1

Related Questions