无法在Azure应用服务上打开数据库文件

k5hmc34c  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(222)

我已经将FlaskApp部署到Azure。我有一个SQLLite db文件,它在本地打开,但在App Service上它抛出一条消息,说“无法打开数据库文件”。我试过给出绝对和完整的路径,但似乎不起作用。

DATABASE = "DBN\\LeaveApp.db"  # DB file initialization
        self.conn_db = sqlite3.connect(DATABASE)  # connection opening  instantiation
        print("open database successfully")
        self.c = self.conn_db.cursor()

在Azure App Service上:

有什么想法吗?

zf2sa74q

zf2sa74q1#

  • 首先,我在本地安装了SQLite并创建了.db文件。

  • pavandb.db数据库中添加了示例数据。然后,创建了一个flask应用程序来从本地检索数据。
    dbsample py:

from flask import Flask, render_template
import sqlite3

app = Flask(__name__)

@app.route('/')
def index():
    # Connect to the SQLite database
    connection = sqlite3.connect('pavandb.db')
    cursor = connection.cursor()

    # Execute the SQL query
    query = "SELECT name, age, salary FROM employees"
    cursor.execute(query)

    # Fetch the results
    results = cursor.fetchall()

    # Close the database connection
    connection.close()

    # Pass the results to the template and render it
    return render_template('index.html', results=results)

if __name__ == '__main__':
    app.run()
  • 在本地成功运行。

  • 然后部署在App Service(Web App)中。

  • 现在我可以从pavandb.db数据库的employees表中检索所有行。

  • 确保DBN文件夹和pavandb.db文件与Flask应用程序文件位于同一目录中。

相关问题