1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00
Files
sql-server-samples/samples/connect/python/pyodbc/windows
2016-07-25 00:48:25 -07:00
..
2016-07-25 00:48:25 -07:00
2016-07-25 00:48:25 -07:00

Connect to SQL Database by using Python on Windows using pyodbc

[Python code sample] (sample_python_windows.py) that runs on a Windows computer. The sample and connects to Microsoft SQL Database by using the pyodbc driver.

Requirements

Install the required modules

Navigate to your Python directory where the pip installer is located. For example C:\Python27\Scripts>.

####Install pyodbc

pip install pyodbc

Note: Instructions to enable the use pip can be found here

Create a database and retrieve your connection string

For simplicity we will create an Azure SQL Database for the sample. You can use the same sample for an on-premise SQL Server instance. 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.

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.