title: Connect to MSSQL Database using Flask-SQLAlchemy
body: <p>I'm trying to connect to a local MSSQL DB through Flask-SQLAlchemy.</p>
  
  <p>Here's a code excerpt from my <code>__init__.py</code> file:</p>
  
  <pre><code>from flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'mssql+pyodbc://HARRISONS-THINK/LendApp'
  db = SQLAlchemy(app)
  
  SQLALCHEMY_TRACK_MODIFICATIONS = False
  </code></pre>
  
  <p>As you can see in SQL Server Management Studio, this information seems to match:</p>
  
  <p><a href="https://i.stack.imgur.com/ppbky.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ppbky.png" alt="enter image description here"></a></p>
  
  <p>Here is the creation of a simple table in my <code>models.py</code> file:</p>
  
  <pre><code>from LendApp import db
  
  class Transaction(db.model):
      transactionID = db.Column(db.Integer, primary_key=True)
      amount = db.Column(db.Integer)
      sender = db.Column(db.String(80))
      receiver = db.Column(db.String(80))
  
      def __repr__(self):
          return 'Transaction ID: {}'.format(self.transactionID)
  </code></pre>
  
  <p>I am then connecting to the database using a Python Console within Pycharm via the execution of these two lines:</p>
  
  <pre><code>&gt;&gt;&gt; from LendApp import db
  &gt;&gt;&gt; db.create_all()
  </code></pre>
  
  <p>This is resulting in the following error:</p>
  
  <pre><code>DBAPIError: (pyodbc.Error) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
  </code></pre>
  
  <p>The only thing that I can think of is that my database connection string is incorrect. I have tried altering it to more of a standard Pyodbc connection string and including <code>driver={SQL SERVER}</code> but to no prevail.</p>
  
  <p>If anyone could help me out with this it would be highly appreciated.</p>
  
  <p>Thanks</p>