You must re-open the database connection for every script.
Whenever your script stops, all the identifiers it created (for databases,files, sockets, whatever) become invalid. So you cannot write them to a file or database and use them in another script after the script that created them dies.