Jdbc connection error from Google Apps Script

后端 未结 4 1130
离开以前
离开以前 2021-01-02 11:27

I have created a Google Cloud Project MySQL database to use in conjunction with the Jdbc service provided by Google Apps Script. Everything went as planned with the connecti

4条回答
  •  自闭症患者
    2021-01-02 11:33

    I think this is a permission issue in your second account. Necessary information are missing in your question. But, the secound account, if run as a another user, won't necessarily have your sqlservice authorization. The permission,

    https://www.googleapis.com/auth/sqlservice

    Manage the data in your Google SQL Service instances

    is required to use Jdbc.getCloudSqlConnection(url), while Jdbc#getConnectionUrl() just requires external link connection permission

    https://www.googleapis.com/auth/script.external_request

    I believe that you can only connect to sql instances owned by you with getCloudSqlConnection() which doesn't even require external connection permission. This method probably calls your sql instance internally.

    References:

    • Jdbc#getCloudConnection

    • Jdbc#getConnection


    Conclusion

    To connect to any external service, you need external_request permission. But, You don't need that permission to connect to your own documents say, Spreadsheets owned by you/have edit access permission - through SpreadsheetApp.openByUrl. I believe it's the same thing with Jdbc.getCloudSqlConnection(). It calls your Google sql internally - So, even if you grant external request permission, It won't work. What will work for this method is1.Installable triggers (which runs as you). One more thing I'll try is: 2. Add the second account also as owner in GCP-IAM(may not work though).

提交回复
热议问题