You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: azure-sql/database/azure-sql-passwordless-migration-python.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,10 +48,13 @@ Create a user in Azure SQL Database. The user should correspond to the Azure acc
48
48
Migrating to passwordless connections with [mssql-python](/sql/connect/python/mssql-python/python-sql-driver-mssql-python) requires only a connection string change. The driver has built-in support for Microsoft Entra authentication modes, eliminating the need for manual token handling.
To update the referenced connection string (`AZURE_SQL_CONNECTIONSTRING`) for local development, use the passwordless connection string format with`ActiveDirectoryDefault` authentication:
67
+
To update the referenced connection string (`AZURE_SQL_CONNECTIONSTRING`) for local development, create a `.env` file in your project folder with the passwordless connection string format using`ActiveDirectoryDefault` authentication:
`ActiveDirectoryDefault` automatically discovers credentials from multiple sources (Azure CLI, environment variables, Visual Studio, etc.) without requiring interactive login. This is convenient for development but adds latency as it tries each credential source in sequence.
Copy file name to clipboardExpand all lines: azure-sql/database/azure-sql-python-quickstart.md
+19-10Lines changed: 19 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,7 @@ For details and specific instructions for installing the `mssql-python` driver,
78
78
fastapi
79
79
uvicorn[standard]
80
80
pydantic
81
+
python-dotenv
81
82
```
82
83
83
84
1. Install the requirements.
@@ -88,16 +89,20 @@ For details and specific instructions for installing the `mssql-python` driver,
88
89
89
90
## Configure the local connection string
90
91
91
-
For local development and connecting to Azure SQL Database, add the following `AZURE_SQL_CONNECTIONSTRING` environment variable. Replace the `<database-server-name>` and `<database-name>` placeholders with your own values. Example environment variables are shown for the Bash shell.
92
+
For local development, create a `.env` file in your project folder to store your connection string. This keeps credentials out of your code and source control.
93
+
94
+
1. In the project folder, create a new file named `.env`.
95
+
96
+
1. Add the `AZURE_SQL_CONNECTIONSTRING` variable with your connection string. Replace the `<database-server-name>` and `<database-name>` placeholders with your own values.
92
97
93
98
The mssql-python driver has built-in support for Microsoft Entra authentication. Use the `Authentication` parameter to specify the authentication method.
94
99
95
100
## [DefaultAzureCredential](#tab/sql-default)
96
101
97
102
`ActiveDirectoryDefault` automatically discovers credentials from multiple sources (Azure CLI, environment variables, Visual Studio, etc.) without requiring interactive login. This is convenient for local development but is slower due to credential discovery.
In Windows, Microsoft Entra Interactive Authentication can use Microsoft Entra multifactor authentication technology to set up connection. In this mode, an Azure Authentication dialog is triggered and allows the user to input credentials to complete the connection.
> Use caution when managing connection strings that contain secrets such as usernames, passwords, or access keys. These secrets shouldn't be committed to source control or placed in unsecure locations where they might be accessed by unintended users.
131
+
> Use caution when managing connection strings that contain secrets such as usernames, passwords, or access keys. These secrets shouldn't be committed to source control or placed in unsecure locations where they might be accessed by unintended users. Add `.env` to your `.gitignore` file to prevent accidentally committing secrets.
127
132
128
133
---
129
134
@@ -137,24 +142,28 @@ You can get the details to create your connection string from the Azure portal:
137
142
138
143
In the project folder, create an *app.py* file and add the sample code. This code creates an API that:
139
144
145
+
- Loads configuration from a `.env` file using `python-dotenv`.
140
146
- Retrieves an Azure SQL Database connection string from an environment variable.
141
147
- Creates a `Persons` table in the database during startup (for testing scenarios only).
142
148
- Defines a function to retrieve all `Person` records from the database.
143
149
- Defines a function to retrieve one `Person` record from the database.
144
150
- Defines a function to add new `Person` records to the database.
0 commit comments