Connect AppMaker to Google SQL - google-cloud-sql

I tried to connect AppMaker to an existing Google SQL database without success. In Google Cloud, I created a second generation instance (europe-west1) and allow every IP (for the test). Next, I created a user, connected Workbench with the database and created a schema. Without problems.
In AppMaker I use the following address to connect to the database:
[domainName:]myprojectID:regionName:myinstanceID/mydatabase
(with and without domain)
Feedback:
Unable to connect to Google Cloud SQL instance.
The Google Cloud SQL address may be incorrect or this App Maker editor may not have permission to access the database. You can find more information about using Google Cloud SQL in our documentation.
How can I connect to Google SQL with AppMaker?
Thanks.

The process I followed to connect to the database is the following:
Create a second generation instance by following the steps here (Please make sure to follow the steps only for "Create a Cloud SQL instance" and then create a database inside that instance)
Now, go to the IAM & ADMIN section of your project. Click on the blue "add" member option on the top. Type "appmaker-maestro#appspot.gserviceaccount.com" on the "Members" field and from the "Roles" dropdown select Project->Editor
Return to your second generation SQL instance and copy the value of the Instance connection name property of your instance. Example:
Follow the steps for second generation found here to connect to the database from AppMaker and when asked for the instance address, type the value you copied on the previous step and add /yourdatabase at the end of it. For example: my-foto-app:us-central1:myinstance/userphotodatabase
You should now be asked to enter the user and password. Do so and you are finished.
Please note that I haven't tested out this with a europe location but only on a us central location. I hope this helps and works!

Second generation instances are not yet supported by App Maker, switch to first generation and it will work.

FYI, 2nd gen Cloud SQL is supported bv App Maker and has been for awhile.
As of today, Postgre is not yet supported.

Related

How do I set up MongoDB Atlas?

I need to work with MongoDB Atlas but unsure how to set it up? I have never used Cloud DB before. I want to make sure that I can let everyone connect to it without an API Key
Sign up with MongoDB Atlas
Go to the MongoDB Atlas website and sign up: https://www.mongodb.com/cloud/atlas
Fill in the form to create your account:
Once you are in, it will ask you to select a path for clustering. Select the Free option at this time.
Then it will ask you to create a starter cluster
All default settings are fine
Encourage you to rename your cluster and then Click Create
After about a minute, it’s created
Click on Collections button
For first time use it will ask if you want sample data
If you just need sample data to play with, click on Load a Sample Dataset
For that, just follow the prompts
All your data will load
Next click on Database Access, we will need to create a database user
Keep it easy, use a password and select the role that this user should have
Click Add User
Now we need to white List IPs
Click on Network Access
Then click on Add IP, then "allow access from anyone" (No need for API Key)
You can always change this later but for testing purposes, you can select this
Click Confirm
Wait until it states that it’s active
Now click on Cluster and Connect
Select Connect using MongoDB Compass
Leave settings as is and copy the string and make the changes
For our purposes, here is our connection string.
mongodb+srv://Cam_user:Password1#camcluster.l41xe.mongodb.net/sample_airbnb

GCP cloud sql postgres connection count missing

I have a problem after migration postgres instance from 9 to 12, we were following this method https://cloud.google.com/sql/docs/postgres/upgrade-db.
Before migration, I had a graph whit active connections on instance page and after the migration (on the new instance - postgres 12) - I don`t have values on this graph.
I am receiving a message like "No data is available for the selected time frame."
Also if I am run a query like "SELECT * FROM pg_stat_activity;"
I see the number of connections.
At this moment the graph section for connections count in Postgres12 is not currently supported. The Cloud SQL engineering team is working on implementing this feature as its already implemented for other Postgres versions. This is not just happening to you, it is a general behaviour.
The best way to report an issue is to use a Google Issue Tracker1, where you can share your project information.
I found that same error reported by another client but I cannot relate it to your scenario.

Connect to postgresql database using google apps script from google spreadsheet

I've seen this question asked a few times before, most notably this StackOverflow question: Automate Google Spreadsheet data load from external database
and here on Google issue tracker:
https://issuetracker.google.com/issues/36752790
but I'm looking for a more up-to-date answer.
I have a cloud-SQL instance of a PostgreSQL database running on GCP. I would like to automatically connect to it and populate a spreadsheet on a daily basis, which is possible for MySQL databases.
The docs on Google say to use a jdbc socket factory to connect to a PostgreSQL db using the format:
"jdbc:postgresql://google/<DBNAME>?"
"socketFactory=com.google.cloud.sql.postgres.SocketFactory"
"&socketFactoryArg=<InstanceName>"
I've also tried the format (slightly different) from the Google GitHub page (linked under the example in the docs):
"jdbc:postgresql://google/<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<POSTGRESQL_USER_NAME>&password=<POSTGRESQL_USER_PASSWORD>"
After creating a url I run:
var conn = Jdbc.getConnection(dbUrl)
But get this error:
Connection URL uses an unsupported JDBC protocol.
I'm wondering if this is possible yet or if it is user error?
I found JDBC in Google Sheets, especially for Postgres, to be buggy, so I built SeekWell which lets you automatically send data from Postgres to Sheets. You can also also sync changes from Sheets back to a database and schedule refreshes daily, hourly or every five minutes.
Disclaimer: I built this.

Staging environment for Azure Mobile Services using Code First Migrations

I seem to have trouble understanding a concept with Azure Mobile Services that are using .NET backend with Code First and migrations enabled.
Currently I have deployed a "productive" instance of AMS, let's say it's called "AMD". It is running at amd.azure-mobile.net. Database structure has been created using Enable-Migrations and Add-Migration. This is all fine now for this productive instance, it is running and is fully functional.
Now I want to create an INT instance to have a separate environment for tests etc. I want to name it differently, say "AMDINT". It should run at amdint.azure-mobile.net and should also have a separate database, to make it impossible to break stuff in production.
Originally I thought I could pull it off like this:
1) Create the new instance under amdint.azure-mobile.net with a new database to go with it
2) Create a web.config transform for a newly created configuration called "INT" (primarily to change the MS_MobileServiceName value to the new name)
3) Download the publishing profile of the new instance, import it, make it use the "INT" configuration and deploy it
The new bits apparently get deployed, but whenever I hit an endpoint that requires DB access, an error will be generated in the logs and it says
Database initialization failed. Could not initialize one or more objects in schema 'amdint'. Please ensure that the database connection string is correct. For more details on the error, please see the inner exception. ---> System.InvalidOperationException: Database initialization failed. Could not initialize one or more objects in schema 'amdint'. Please ensure that the database connection string is correct. For more details on the error, please see the inner exception. ---> System.Data.SqlClient.SqlException: User does not have permission to perform this action.
So I used Azure User Management Console (AUMC) to see if permissions were missing for the user that is being specified in the connection string in the configuration tab of the new service, but the user was present for that database. I also edited the user's permissions to include every possible right, but this did not change anything.
Then I noticed that the migrations files specify a database schema for the Up() and Down() methods. For a test, I changed these strings from "amd.tablename" to "amdint.tablename" and was pretty confident I had nailed it.
However, this still brought the same error. So I used the database user's credentials from the connection string and opened database editor from the management console in the browser, and saw that with all the added rights it can edit the database schema just fine (created and deleted a table for testing purposes). However, no single table has been created by the Initializer; the database was blank.
But since I was able to edit, I somehow believe that either the error message about insufficient permissions is misleading or that I am looking at the wrong place.
Does anyone know of a way to accomplish what I am trying to do? I don't want to have separate Visual Studio projects for production and INT, obviously.
I think what you're running into is the issue that Mobile Services creates a special schema user that has rights to only tables in that schema. This schema has the same name as your mobile service. So, even if the two databases are on the same DB server, the connection string for a DEV mobile service wouldn't work for PROD, and vice versa.
Here are some suggestions to make your setup easier:
In the Azure Portal, Mobile Services doesn't allow modifying the connection string that it creates for you, which is called MS_TableConnectionString. I recommend that in your case, you create a new connection string with a different key and use that for each of your services, e.g., AMD_TableConnectionString. Make sure that for each service, the database user has access to each schema (more on that in a minute).
To use the new connection string, change your super constructor call in your DbContext class, e.g., base("name=AMD_TableConnectionString").
Use the application setting MS_MobileServiceName in your web.config and/or the Azure Portal to set the schema for your service. This is use by the Mobile Service Entity Framework initializer.
NOTE: If you're already using separate databases for DEV and PROD, you have the option of using the same schema name for both your DEV and PROD instances, which might make testing and setup easier.
Either way, the database user in the connection string must have full permissions to whatever schema name you specify in MS_MobileServiceName.
(You probably have this part working.) Make sure that the Mobile Services SQL Generator is run. It will automatically run if you set an Entity Framework database initializer, but some folks like to have all database changes done through DB migrations. In that case, follow this tutorial here: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations/#using-code-first-migrations-without-an-initializer

RealStudio and PostgreSQL

To connect to the database I use this example. But I can't find lessons on how to create a database.
For example:
connect to server
create new database
do something
drop database
close connection
Can anybody show me how to do it?
Thanks!
Follow the manual on how to create a database cluster:
http://www.postgresql.org/docs/9.1/interactive/creating-cluster.html
The database and users are created only once and you can use the client applications for that. Or are you trying to do it automatically as part of a software install package? After that you connect to it as many times as needed.
Since you are creating a new database and then dropping it, why not use the built-in SQLite database? You can do a completely in-memory database that will be lightning fast (unless you fill up available RAM).
I believe you can create databases by issuing standard SQL commands just as you can create tables in a database, as long as you are using a user (e.g. admin or similarly entitled user) that has permissions to create new databases.
So, all you need is to connect to the DB with the right user and then issue SQL commands with db.SQLExecute, such as "create database newDBname".