A script that was working fine on 100 records per batch choked when I fed it 1,000 records.
It gave:

mysql.connector.errors.OperationalError: 1040 (08004): Too many connections

So I went ahead and made sure to connect.close() everywhere that I opened a connection, and the script made it much further but eventually crashed, giving the same error.
Obviously, increasing the connection limit would only encourage sloppy coding? It would be better if I developed a methodology to prevent this type of crash. Because if this were PHP it wouldn't be happening, I admit that.

How can I prevent this type of error from happening again, short of switching to PHP?

Are you connecting to MySQL with persistent connections? What happens if you don't use persistent connections?

Also, I'm confused what you mean about it complaining about too many connections simply by you changing how many records a single connection works with?

So I went ahead and made sure to connect.close() everywhere that I opened a connection

How many times do you have a single script opening and closing a connection to MySQL? Is this a web script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.