Below is the code I am using while working on a Python flask website to access SQL Server. It is with accessing Database section I am unable to use the connection string , can I get some help on that please.
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.engine import URL
import urllib
from flask import app
import pyodbc
app = Flask(__name__)
db_env = 'dev'
if db_env == 'dev':
app.debug = True
connection_string = "DRIVER={SQL Server Native Client 17.0};SERVER=localhost;DATABASE=PlatformDatabase;UID=sa;PWD=999999"
connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})
else:
app.debug = False
app.config['SQLALCHEMY_DATABASE_URI'] = ''
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app) #Database Object
class knowshare(db.Model):
__database__ = 'PlatformDatabase'
__tablename__ = 'knowshare'
id = db.Column(db.Integer, primary_key=True)
customer = db.Column(db.String(200), unique=True)
dealer = db.Column(db.String(200))
rating = db.Column(db.Integer)
comments = db.Column(db.Text())
def __init__(self, customer, dealer, rating, comments):
self.customer = customer
self.dealer = dealer
self.rating = rating
self.comments = comments