input: Write a python function to delete a record from a SQLite database table named 'records' using Flask and handle potential exceptions.
  assert delete_record(1) == "Record deleted successfully"
  assert delete_record(999) == "Record not found"
output: def delete_record(record_id):
      from flask import Flask, jsonify
      import sqlite3
  
      app = Flask(__name__)
  
      try:
          conn = sqlite3.connect('database.db')
          cursor = conn.cursor()
  
          cursor.execute("DELETE FROM records WHERE id = ?", (record_id,))
          conn.commit()
  
          if cursor.rowcount == 0:
              return "Record not found"
  
          return "Record deleted successfully"
  
      except sqlite3.Error as e:
          return f"An error occurred: {e}"
  
      finally:
          conn.close()