Skip to content

Commit 165cd6d

Browse files
dlevy-msft-sqlrwestMSFT
authored andcommitted
Added additional pip command for dotenv
1 parent 7867984 commit 165cd6d

2 files changed

Lines changed: 70 additions & 29 deletions

File tree

docs/connect/python/mssql-python/python-sql-driver-mssql-python-quickstart.md

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This quickstart describes installing Python, and mssql-python then
44
author: dlevy-msft-sql
55
ms.author: dlevy
66
ms.reviewer: vanto, randolphwest
7-
ms.date: 06/26/2025
7+
ms.date: 07/09/2025
88
ms.service: sql
99
ms.subservice: connectivity
1010
ms.topic: quickstart-sdk
@@ -14,7 +14,7 @@ ms.custom:
1414

1515
# Quickstart: Connect with the mssql-python driver for Python
1616

17-
In this quickstart, you connect a Python script to a database that you have created and loaded with sample data. You use the `mssql-python` driver for Python to connect to your database and perform basic operations, like reading and writing data.
17+
In this quickstart, you connect a Python script to a database that you created and loaded with sample data. You use the `mssql-python` driver for Python to connect to your database and perform basic operations, like reading and writing data.
1818

1919
[mssql-python documentation](https://github.com/microsoft/mssql-python/wiki) | [mssql-python source code](https://github.com/microsoft/mssql-python/wiki) | [Package (PyPi)](https://pypi.org/project/mssql-python/)
2020

@@ -37,7 +37,7 @@ In this quickstart, you connect a Python script to a database that you have crea
3737
Follow these steps to configure your development environment to develop an application using the `mssql-python` Python driver.
3838

3939
> [!NOTE]
40-
> This driver uses the [TDS](/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec) protocol, which is enabled by default in SQL Server, SQL database in Fabric and Azure SQL Database. No extra configuration is required.
40+
> This driver uses the [Tabular Data Stream (TDS)](/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec) protocol, which is enabled by default in SQL Server, SQL database in Fabric and Azure SQL Database. No extra configuration is required.
4141
4242
### Install the mssql-python package
4343

@@ -47,19 +47,46 @@ Get the [`mssql-python` package](https://pypi.org/project/mssql-python/) from Py
4747

4848
1. Install the `mssql-python` package.
4949

50-
```bash
51-
pip install mssql-python
52-
```
50+
### [Windows](#tab/windows)
51+
52+
```bash
53+
pip install mssql-python
54+
```
55+
56+
### [Linux](#tab/linux)
57+
58+
```bash
59+
pip install mssql-python
60+
```
61+
62+
### [macOS](#tab/mac)
63+
64+
```bash
65+
brew install openssl
66+
pip install mssql-python
67+
```
68+
69+
---
70+
71+
### Install python-dotenv package
72+
73+
Get the [`python-dotenv`](https://pypi.org/project/python-dotenv/) from PyPI.
74+
75+
1. In the same directory, install the `python-dotenv` package.
76+
77+
```bash
78+
pip install python-dotenv
79+
```
5380

5481
### Check installed packages
5582

5683
You can use the PyPI command-line tool to verify that your intended packages are installed.
5784

5885
1. Check the list of installed packages with `pip list`.
5986

60-
```bash
61-
pip list
62-
```
87+
```bash
88+
pip list
89+
```
6390

6491
### Create a SQL database
6592

@@ -121,7 +148,7 @@ This quickstart requires the *[!INCLUDE [sssampledbnormal-md](../../../includes/
121148
```
122149

123150
> [!TIP]
124-
> The connection string used here largely depends on the type of SQL database you're connecting to. For more information on connection strings and their syntax, see [connection string syntax reference](../../ado-net/connection-string-syntax.md).
151+
> The connection string used here largely depends on the type of SQL database you're connecting to. If you're connecting to an *Azure SQL Database* or a *SQL database in Fabric*, use the *ODBC* connection string from the connection strings tab. You might need to adjust the authentication type depending on your scenario. For more information on connection strings and their syntax, see [connection string syntax reference](../../odbc/dsn-connection-string-attribute.md).
125152
126153
### Execute a query
127154

@@ -161,7 +188,7 @@ Use a SQL query string to execute a query and parse the results.
161188
```python
162189
records = cursor.fetchall()
163190
for r in records:
164-
print(f"{r.CustomerID}\t{r.OrderCount}\t{r.CompanyName}")
191+
print(f"{r.CustomerID}\t{r.OrderCount}\t{r.CompanyName}")
165192
```
166193

167194
1. **Save** the `app.py` file.
@@ -220,13 +247,13 @@ Execute an [INSERT](../../../t-sql/statements/insert-transact-sql.md) statement
220247

221248
```python
222249
cursor.execute(
223-
SQL_STATEMENT,
224-
(
225-
f'Example Product {productNumber}',
226-
f'EXAMPLE-{productNumber}',
227-
100,
228-
200
229-
)
250+
SQL_STATEMENT,
251+
(
252+
f'Example Product {productNumber}',
253+
f'EXAMPLE-{productNumber}',
254+
100,
255+
200
256+
)
230257
)
231258
```
232259

docs/connect/python/pyodbc/python-sql-driver-pyodbc-quickstart.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This quickstart describes installing Python, and pyodbc then shows
44
author: dlevy-msft-sql
55
ms.author: dlevy
66
ms.reviewer: vanto, randolphwest
7-
ms.date: 06/18/2025
7+
ms.date: 07/09/2025
88
ms.service: sql
99
ms.subservice: connectivity
1010
ms.topic: quickstart-sdk
@@ -14,7 +14,7 @@ ms.custom:
1414

1515
# Quickstart: Connect with the pyodbc driver for Python
1616

17-
In this quickstart, you connect a Python script to a database that you have created and loaded with sample data. You use the `pyodbc` driver for Python to connect to your database and perform basic operations, like reading and writing data.
17+
In this quickstart, you connect a Python script to a database that you created and loaded with sample data. You use the `pyodbc` driver for Python to connect to your database and perform basic operations, like reading and writing data.
1818

1919
[pyodbc documentation](https://github.com/mkleehammer/pyodbc/wiki) | [pyodbc source code](https://github.com/mkleehammer/pyodbc) | [Package (PyPi)](https://pypi.org/project/pyodbc/)
2020

@@ -37,7 +37,7 @@ In this quickstart, you connect a Python script to a database that you have crea
3737
Follow these steps to configure your development environment to develop an application using the `pyodbc` Python driver.
3838

3939
> [!NOTE]
40-
> This driver uses the [TDS](/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec) protocol, which is enabled by default in SQL Server, SQL database in Fabric and Azure SQL Database. No extra configuration is required.
40+
> This driver uses the [Tabular Data Stream (TDS)](/openspecs/windows_protocols/ms-tds/b46a581a-39de-4745-b076-ec4dbb7d13ec) protocol, which is enabled by default in SQL Server, SQL database in Fabric and Azure SQL Database. No extra configuration is required.
4141
4242
### Install the pyodbc package
4343

@@ -47,19 +47,29 @@ Get the [`pyodbc` package](https://pypi.org/project/pyodbc/) from PyPI.
4747

4848
1. Install the `pyodbc` package.
4949

50-
```bash
51-
pip install pyodbc
52-
```
50+
```bash
51+
pip install pyodbc
52+
```
53+
54+
### Install python-dotenv package
55+
56+
Get the [`python-dotenv`](https://pypi.org/project/python-dotenv/) from PyPI.
57+
58+
1. In the same directory, install the `python-dotenv` package.
59+
60+
```bash
61+
pip install python-dotenv
62+
```
5363

5464
### Check installed packages
5565

5666
You can use the PyPI command-line tool to verify that your intended packages are installed.
5767

5868
1. Check the list of installed packages with `pip list`.
5969

60-
```bash
61-
pip list
62-
```
70+
```bash
71+
pip list
72+
```
6373

6474
### Create a SQL database
6575

@@ -69,10 +79,14 @@ This quickstart requires the *[!INCLUDE [sssampledbnormal-md](../../../includes/
6979

7080
[Create a SQL database in minutes using the Azure portal](/azure/azure-sql/database/single-database-create-quickstart)
7181

82+
Copy the `ODBC` connection string from the *Connection strings* tab.
83+
7284
### [SQL database in Fabric](#tab/fabric-sql)
7385

7486
[Load AdventureWorks sample data in your SQL database in Microsoft Fabric](/fabric/database/sql/load-AdventureWorks-sample-data)
7587

88+
Copy the `ODBC` connection string from the *Settings* tab.
89+
7690
### [Microsoft SQL Server](#tab/sql-server)
7791

7892
[AdventureWorks sample databases](../../../samples/adventureworks-install-configure.md)
@@ -121,7 +135,7 @@ This quickstart requires the *[!INCLUDE [sssampledbnormal-md](../../../includes/
121135
```
122136

123137
> [!TIP]
124-
> The connection string used here largely depends on the type of SQL database you're connecting to. For more information on connection strings and their syntax, see [connection string syntax reference](../../ado-net/connection-string-syntax.md).
138+
> The connection string used here largely depends on the type of SQL database you're connecting to. If you're connecting to an *Azure SQL Database* or a *SQL database in Fabric*, use the *ODBC* connection string from the connection strings tab. You might need to adjust the authentication type depending on your scenario. For more information on connection strings and their syntax, see [connection string syntax reference](../../odbc/dsn-connection-string-attribute.md).
125139
126140
### Execute a query
127141

@@ -239,7 +253,7 @@ Execute an [INSERT](../../../t-sql/statements/insert-transact-sql.md) statement
239253
```
240254

241255
> [!TIP]
242-
> Optionally, you can use [`connection.rollback`](https://github.com/mkleehammer/pyodbc/wiki/Connection#rollback) to rollback the transaction.
256+
> Optionally, you can use [`connection.rollback`](https://github.com/mkleehammer/pyodbc/wiki/Connection#rollback) to roll back the transaction.
243257
244258
1. Close the cursor and connection using [`cursor.close`](https://github.com/mkleehammer/pyodbc/wiki/Cursor#close) and [`connection.close`](https://github.com/mkleehammer/pyodbc/wiki/Connection#close).
245259

0 commit comments

Comments
 (0)