简体   繁体   中英

Connect to postgresql instance on Cloud SQL: The Google Cloud SQL API is not enabled for project

I have deployed on appengine a basic java web app that is supposed to connect to a postgresql instance on Cloud SQL (works locally). After deployment It (wrongly?) raise this exception when I browse the page that tries to connect to the DB:

org.postgresql.Driver connect: Unexpected connection error: (Driver.java:271) java.lang.RuntimeException: The Google Cloud SQL API is not enabled for project [ad*****manager-XXXXXXX]. Please use the Google Developers Console to enable it: https://console.cloud.google.com/apis/api/sqladmin/overview?project=ad *****manager-XXXXXXX

  • I have checked that the Google Cloud SQL API is enabled as you can see on that screenshot
  • I have granted the cloud sql editor rights to my app on the project that hosts the instance (Note that the postgresql instance and the web app live in two separate projects.)
  • It is a flex environment app

Here is the part of the code that fails:

Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(dburl, dbuser, dbpwd);

And the connection url:

jdbc:postgresql://google/name_of_my_database?useSSL=false&socketFactoryArg=ad*****manager-XXXXXXX:europe-west1:XXXX-pgdb-preprod&socketFactory=com.google.cloud.sql.postgres.SocketFactory

Actually I had to enable the SQL API not in the project that hosts the DB as said in the error message but in the project that hosts the application

To do so, go in the API section, choose library and search for SQL API (see screenshot below)

screenshot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM