简体   繁体   中英

python flask website running on iis not connecting to sql database when passing login credentials

I am a bit stuck here, so i made a test site to figure this out.

I have a python flask site and I have to use the domain login to login into sql database. Here i wrote a quick test which sends the username and password to my db connection and will display the connection on the screen

@app.route("/", methods =['GET','POST']
def index():
    user = os.environ.get('username')
    pwd = os.environ.get('password')
    dbcon = db.sqlcon(user, pwd)
    return render_template("index.html", dbcon=dbcon

def dbcon(user, pwd):
    a="SQL Server"
    con = pyodbc.connect(f"DRIVER={a};Database=customer;Server=SQL1;Username={user};pwd{pwd}")
    return con

Again, very simple and this works on my local machine. When i upload to the iis server, it does not connect to the database. I tried install an odbc driver on the iis server, but still wouldn't connect.

I also checked to see, when i go onto the site from the server, it does capture my login information.

Any help is duly appreciated

DamnGroundHog

I use flask on IIS and work perfect wit SQL.(thanks from this link ).

First step create SQL authentication user on SQL server with SQL server management.

second step connect with this code:

coonection = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};Server=. ;Database=MyDBName;uid=UserNameWhenCreateUser; pwd=PasswordWhenCreateUser;")   
CU = coonection .cursor()   

result: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM