App Engine to connect cloud sql with error: ApplicationError: 1007 Invalid connection id

166 views
Skip to first unread message

Yongtao Wang

unread,
Nov 23, 2011, 4:31:48 PM11/23/11
to Google Cloud SQL discuss
I am using app engine on python to connect the Cloud SQL, and it
worked well for few days. But from yesterday, I got the error for any
database query:
OperationalError: could not connect: ApplicationError: 1007 Invalid
connection id.

In my python codes, I used singleton pattern to maintain one
connection for all my database operations, and I am not sure that
caused the problem.

Tony Tseng

unread,
Nov 23, 2011, 4:39:14 PM11/23/11
to google-cloud...@googlegroups.com
Hi John,
The connection can become invalid for a variety of reasons. You'll need to check to see if the connection is valid before you use it.

Yongtao Wang

unread,
Nov 23, 2011, 4:47:39 PM11/23/11
to Google Cloud SQL discuss
Hi Tony,

Thanks for your quick reply.
Could you tell me how to valid the connection?

The codes in my local dev environment worked well without any problem,
and it also worked without any problem in App Engine platform before
yesterday. That's so wired. And the problem still exist after I
restart the instance.

Tony Tseng

unread,
Nov 23, 2011, 5:18:53 PM11/23/11
to google-cloud...@googlegroups.com
Connection has a ping() method.
Also it takes roughly the same amount of time to check connection validity as opening a new connection, so it might be easier to open a new connection at the beginning of each request and close it in the end.

Here's the doc:
def ping(self, reconnect=False):
    """Checks whether or not the connection to the server is working.

    If it has gone down, an automatic reconnection is attempted.

    This function can be used by clients that remain idle for a long while, to
    check whether or not the server has closed the connection and reconnect if
    necessary.

    Non-standard. You should assume that ping() performs an implicit rollback;
    use only when starting a new transaction.  You have been warned.

    Args:
      reconnect: Whether to perform an automatic reconnection.

    Raises:
      DatabaseError: The connection to the server is not working.
Reply all
Reply to author
Forward
0 new messages