Connect to SQL Database by using Python on Windows
[Python code sample] (sample_python_win.py) that runs on a Windows computer. The sample and connects to Azure SQL Database by using the pymssql driver.
Requirements
Install the required modules
Install pymssql.
Make sure you choose the correct whl file.
For example : If you are using Python 2.7 on a 64 bit machine choose : pymssql‑2.1.1‑cp27‑none‑win_amd64.whl. Once you download the .whl file place it in the the C:/Python27 folder.
Now install the pymssql driver using pip from command line. cd into C:/Python27 and run the following
pip install pymssql‑2.1.1‑cp27‑none‑win_amd64.whl
Instructions to enable the use pip can be found here
Create a database and retrieve your connection string
See the getting started page to learn how to create a sample database and get your connection string. It is important you follow the guide to create an AdventureWorks database template. The samples shown below only work with the AdventureWorks schema.