I am able to write to the db when connecting outside of the function but unable to write to the database when calling it via the function
    def Metric_Insert():
     cnxn1 = pyodbc.connect('DRIVER='+driver+';SERVER='+SERVER+';PORT=1433;DATABASE='+DATABASE+';UID='+username+';PWD='+ pwd)
     cursor = cnxn1.cursor()
     #print("Connected in Metric_Insert")
     sql9='''Insert into Stage.CBO_Detail_Person(File_Master_ID,Person_CUID,
                            Family_ID,Age,Metric) Values (?,?,?,?,?);'''
     Val9=(File_Master_ID[0],Person_CUID[0],Family_ID[0],'Age','xyz')
     cursor.execute(sql9,Val9)
     cnxn1.commit()
     #print("Connected in Metric_Insert")
     #return
  Metric_Insert()
