1

I currently have a Google Cloud SQL instance with some tables that I've created using the following format:

-- Create Hotel table with hotelNo primary key
CREATE TABLE IF NOT EXISTS Hotel(
    hotelNo INT NOT NULL AUTO_INCREMENT,
    hotelName VARCHAR(255) NOT NULL,
    city VARCHAR(255) NOT NULL,
    PRIMARY KEY(hotelNo)
);

-- Create Room table with roomNo and hotelNo for the composite key (primary)
CREATE TABLE IF NOT EXISTS Room(
    roomNo INT NOT NULL AUTO_INCREMENT,
    hotelNo INT NOT NULL,
    roomType VARCHAR(255) NOT NULL,
    price INT NOT NULL,
    PRIMARY KEY(roomNo, hotelNo)
);

-- Create Booking table with hotelNo, guestNo and dateFrom for the composite key (primary)
CREATE TABLE IF NOT EXISTS Booking(
    hotelNo INT NOT NULL,
    guestNo INT NOT NULL,
    dateFrom DATE NOT NULL,
    dateTo DATE NOT NULL,
    roomNo INT NOT NULL,
    PRIMARY KEY(hotelNo, guestNo, dateFrom)
);

-- Create Guest table with guestNo primary key
CREATE TABLE IF NOT EXISTS Guest(
    guestNo INT NOT NULL AUTO_INCREMENT,
    guestName VARCHAR(255) NOT NULL,
    guestAddress VARCHAR(255) NOT NULL,
    PRIMARY KEY(guestNo)
);

I am building a small application for class that will allow me to connect to my database on the cloud and then perform basic queries against it. My tables are already loaded with some data so that I am able to carry out basic CRUD operations.

I was wondering how, using C# and from my local machine I could connect to this instance. I have activated the Google SQL API and have downloaded the Google NuGet package but am still having some difficulty figuring out the rest.

I have read some of Google's documentation on this but am hoping to find a more straightforward and simple answer from the community.

Any ideas on how I should move forward? At least for now, I'd like to just be able to simply connect and possibly do a SELECT * FROM Hotel query and see the results on the command prompt.

James Z
  • 12,209
  • 10
  • 24
  • 44
User 5842
  • 2,849
  • 7
  • 33
  • 51
  • Possible duplicate of [How to connect Google Cloud SQL with C#](https://stackoverflow.com/questions/52457709/how-to-connect-google-cloud-sql-with-c-sharp) – Bradley Grainger Sep 22 '18 at 21:07

0 Answers0