Move your code to set up the database connection to a function and call the function before calling app.run()
SC = None
def setupdb():
global SC
db = getConnection("db")
SC = SearchClass(db)
SC.refreshArray()
if __name__== "__main__":
setupdb()
app.run()