Popular Help Content

No popular content.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
titleGenerating a connection string
from urllib.parse import quote_plus

# change these values to match your Azure database
server = 'tcp:your-azure-server.database.windows.net'
database = 'your-database-nametest'
username = 'yourusername'
password = '***'   

# these should not usually need to change
driver = '{ODBC Driver 1718 for SQL Server}'
port = 1433

odbc_str = f'DRIVER={driver};SERVER={server};PORT={port};DATABASE={database};UID={username};PWD={password}'
sqlalchemy_str = 'mssql+pyodbc:///?odbc_connect=' + quote_plus(odbc_str)

print(sqlalchemy_str)  # use this value in the data export tool

# optionally test your connection
from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_str)
query = "select * from <table_name>"
print(engine.execute(query).fetchall())

...