Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the root error behind "Failed to establish a database connection. Check connection string, username and password."

Looking through google and stackoverflow, I found a number of questions asking about "Failed to establish a database connection. Check connection string, username and password." However, I cannot find anyone that has found what the underlying error is.

I am trying to write my first google script with a database connection; I have a mysql and oracle jdbc getConnection, both of which spawn this error. I have checked, double- and triple-check the connection information to no avail. I know the databases are accessible (can get in through other clients from several different machines like php on a linux box, sql developer on various windows PCs at home and work). How do I determine what the real error is? The error as presented to me is way too generic and abstract.

Environment: Using a script in a Google Spreadsheet (thus inheriting whatever environment is established by google). I am attempting to use the Google API jdbc and have no further knowledge of the environment variables.

Using the following syntax:

var url = "jdbc:mysql://mysql.cb-pta.com:3306/u4lottery";
var conn = Jdbc.getConnection(url, user, password); 

Again, user and password have been verified.

like image 585
sacrophyte Avatar asked Nov 11 '12 13:11

sacrophyte


2 Answers

There is a known bug which causes problems with jdbc connections using hostnames. Try using an Ip address instead.

Bizarre, but true.. I lost almost 2 days with this bug....

Here is the link to the bug report....

like image 88
mgmonteleone Avatar answered Oct 20 '22 01:10

mgmonteleone


Just for sake of others finding this older thread. I also had trouble using Apps Script to connect to a Google CloudSQL instance, and had to change from:

Jdbc.getCloudSqlConnection('jdbc:google:rdbms://<IP>/<DB_NAME>', '<USER>', 'PASSWORD');

to standard JDBC MySQL (which worked):

Jdbc.getConnection('jdbc:mysql:// ...same as above...

Also, beware and DO NOT include a '/' behind the DB_NAME - this will also cause failure with user/passwd error message!

One more thing to check is that you have proper firewall settings - to allow access from the source IP you are coming from (in the event of Apps Script, this is likely Google's servers - not you client browser's IP). You may have to open it up to all (0.0.0.0/0)

like image 40
kgingeri Avatar answered Oct 19 '22 23:10

kgingeri