gpt4 book ai didi

python - 需要帮助将 Flask-SQLAlchemy 连接到 MS SQL Server 2008R2

转载 作者:行者123 更新时间:2023-11-28 19:08:07 25 4
gpt4 key购买 nike

难以正确连接到数据库:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

engine = SQLAlchemy.create_engine()

app.config['SQLALCHEMY_DATABASE_URI'] = 'mssql-pyodbc://EVERETT-
PC\\SQLEXPRESS/iNcentDev?trusted_connection=yes'

db = SQLAlchemy(app)
SQLALCHEMY_TRACK_MODIFICATIONS = False

class Payroll(db.Model):
__tablename__ = 'pay.PayRoll'
pk = db.Column('id', db.Integer, primary_key=True)
CreateDate = db.Column('CreateDate', db.DateTime)

最佳答案

这对我有用:

import urllib
params = urllib.parse.quote_plus("DRIVER={SQL Server};SERVER=SERVER_NAME;DATABASE=DB;UID=user;PWD=password")
engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)

关于python - 需要帮助将 Flask-SQLAlchemy 连接到 MS SQL Server 2008R2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com