Forums

noob too many sql connections

Good Evening

I'm sure this a dim question, but I'm struggling to understand the limitation on connections to your sql database(s). I have an smartphone app that could make hundreds of queries to a db at the same time, but I thought the limit was somewhere in the thousands, so I wasn't worried. However, when I was testing something (and had maybe 6 sql consoles open) when I tried to connect again it said the max number of connections was exceeded. Am I missing something?

I will add a line to close the connection after each query, but is it the case that the max number of remote connections is around 6? or is it just a limit on the sql consoles?

I am using the create.engine function to send raw sql queries from a route if that makes any difference:-

from sqlalchemy import create_engine

engine = create_engine("mysql://paulalsmxxxxxxxxxxxxxxxthonanywhere-services.com/paulalsmith1000$shusic")

with engine.connect() as connection: query = "CREATE TABLE test_table (id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY, member_name varchar(20), push_device_key varchar(150))" result = connection.execute(query)

Sorry, while I'm here, could I ask just one quick general question (to general to answer really, but there we are)?

When I use flask / sqlalchemy to query the database, it all works fine, ie for example the above table is created, but when you test it on Postman it returns an internal server error (to clarify, the webapp is just used to run scripts / query databases, there is no associated website/html.

Sorry for the waffle, but any help would be vvvv much appreciated.

Kind regards

Paul

We have a limit on the number of MySQL connections that each user can have at any time to prevent careless users from using too many and slowing down the database for everyone. The limit is based on the number of web workers that your account has with a few extra for management and other processes. In general, it's a good idea to manage your connections carefully so that you do not keep opening new ones and also ensure that you close them (even when there is an expcetion)

When you get a 500 error, look in your error and server logs for details of the exception that you can use to start debugging. In the case of Postman failing, my guess would be that you're either missing something that the code requires or that something is in the wrong format.

Hi Glen

Thanks v much for your reply. Could I just ask a further question re the sql connections?

Say 20 people or 200 people have my app and all make a call to the db at the same time, I presume from your answer that that would be a problem.

That said could you point me in the direction of what sort of sql hoster I should look for? That is designed for potentially large numbers of simultaneous connections.

Many thanks for your help.

Kind regards

Paul

There will never be more people hitting your database from your web app than the number of workers you have. All the remaining requests have to wait for the free worker. Eventually, that could result in an error if no worker is free in time. You can upgrade your account to increase the number of web workers.