title: Use Managed Identity to authenticate Azure App Service to SQL Database
body: <p>I am trying to connect a Python Flask app running in Azure App Service Web App to an Azure SQL Database.
  The works just fine when I use SQL authentication with username and password.</p>
  
  <p>Now I want to move to using the Web Apps managed identity.
  I have activated the system-assigned managed identity, created a user for it in SQL and added it to the db_datareader role.</p>
  
  <p>I am connecting with SqlAlchemy using a connection string like this</p>
  
  <pre><code>params = urllib.parse.quote_plus(os.environ['SQL_CONNECTION_STRING'])
  conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
  engine_azure = db.create_engine(conn_str,echo=True)
  </code></pre>
  
  <p>The connection string is stored as an application setting, and its value is</p>
  
  <pre><code>"Driver={ODBC Driver 17 for SQL Server};Server=tcp:&lt;server&gt;.database.windows.net,1433;Database=&lt;database&gt;;Authentication=ActiveDirectoryMsi;"
  </code></pre>
  
  <p>I expected this to be all I need to do, but now my app is not starting.
  The logs report a timeout when connecting to the database.</p>
  
  <p>How can I fix this?</p>