質問

I have no trouble connecting to the live database locally using port forwarding, but when we go to connect from the openshift gear, we get errors. Let me begin with the code:

Here is the connection variable

var connectionpool = mysql.createPool({
         host     : process.env.OPENSHIFT_MYSQL_DB_HOST,
         port     : process.env.OPENSHIFT_MYSQL_DB_PORT,
         user     : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
         password : process.env.OPENSHIFT_MYSQL_DB_PASSWORD,
         database : 'stembuds',
         socket   : process.env.OPENSHIFT_MYSQL_DB_SOCKET
     });

Here is an example of a query:

app.get('/answerDB/:course?/:answerID?', function(req, res){
var course = req.param('course');
var answerID = req.param('answerID');
connectionpool.getConnection(function(err, connection){
    if(err){
        console.error('CONNECTION error: ',err);
        res.statusCode = 503;
        res.send({
            result: 'error',
            err:    err.code
        });
    }
    if (course === undefined && answerID === undefined) {
        connection.query('SELECT * FROM questions WHERE counter = 0', function(err, rows, fields){
            if (err) {
                console.error(err);
                res.statusCode = 500;
                res.send({
                    result: 'error',
                    err:    err.code
                });
            }
            for(var i in rows){
                var newCourse = rows[i].course;
                newCourse = courses[newCourse];
                rows[i].course = newCourse;
            }
            res.send(rows);
            connection.release();
        });
    }

Here are some errors we receive.

First is an error in the console of Chrome:

GET http://**.rhcloud.com/answerDB 503 (Service Temporarily Unavailable)

But sometimes we get a proxy error:

GET http://**.rhcloud.com/exploreDB 502 (Proxy Error)

Additionally, I have been running the command rhc tail -a nodejs and here is the error I am receiving

 CONNECTION error:  { [Error: ER_ACCESS_DENIED_ERROR: Access denied for user          'adminMYXaSuf'@'127.11.28.130' (using password: YES)]
  code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlState: '28000',
  fatal: true }
TypeError: Cannot call method 'query' of undefined
    at /var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/routes/site.js:172:15
    at Pool.<anonymous> (/var/lib/openshift/5303aee55973ca4092000084/app-    root/runtime/repo/node_modules/mysql/lib/Pool.js:49:16)
    at Handshake.Sequence.end (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24)
    at Handshake.ErrorPacket (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/sequences/Handshake.js:93:8)
    at Protocol._parsePacket (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:202:24)
    at Parser.write (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Parser.js:62:12)
    at Protocol.write (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:37:16)
    at Socket.<anonymous> (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/Connection.js:72:28)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:720:14)

Now it says cannot call method query of undefined. We thought that was strange, so we changed 'connection.query' to 'connectionpool.query' and it then told us that it cannot call method release of undefined. So we changed 'connection.release()' to 'connectionpool.release()' and it told us that the object # has no method release. So I am taking that part of the error with a grain of salt.

We have no idea why it wont connect. Any information would be greatly appreciated - Thanks.

役に立ちましたか?

解決

If your application code works locally while connecting to your remote OpenShift-hosted DB (using rhc port-forward), then I would suspect that your app may have some undocumented dependencies.

It could be that you've installed something locally (or globally) in your dev environment, without including that dep in your app's package.json file.

Make sure that everything your app needs in order to run in a fresh environment is included in your app's package.json file before pushing it to OpenShift.

npm install my_dependency --save

I've written up some additional notes that might be useful for testing locally with a port-forwarded connection to an OpenShift-hosted DB: https://www.openshift.com/blogs/set-up-local-access-to-openshift-hosted-services-with-port-forwarding

他のヒント

Did you create that database name? It should be the name of your application. You can use the OPENSHIFT_APP_NAME environment variable for your database name. Can you ssh into your gear and connect to mysql without any issues? Also, are you trying to connect to the database on your openshift gear from your local machine or from your openshift gear?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top