Closing MySql Connection in Drupal7
The specific function you are looking for in the database abstraction API is db_close() but you may be able to solve your problem through another route by increasing your max connections. 

See this earlier thread on drupal.stackexchange for guidance on increasing max_connections. You might also be having a problem with slow / stalled queries that are trying up limited query slots, this thread offers advice on how to debug.