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
* Update Python quickstarts: Azure CLI auth, macOS tips, new bulk-copy quickstart, bug fixes
- Recommend Azure CLI (ActiveDirectoryDefault) for macOS across all mssql-python quickstarts
- Clarify that both ActiveDirectoryInteractive and ActiveDirectoryDefault work on macOS
- Add full 4-tab auth pattern to connect-query-python.md
- New bulk-copy quickstart using mssql-python + pyarrow/Parquet
- Fix SalesLt casing to SalesLT in jupyter and rapid-prototyping quickstarts
- Fix SQL injection in rapid-prototyping quickstart (int cast + template)
- Fix stray whitespace in rapid-prototyping SQL queries
- Fix 'Prefer to not' phrasing to 'Don''t want to' across all quickstarts
- Update overview index ms.date
* Use parameterized queries in rapid-prototyping quickstart
* Clarify destination database requirements in bulk copy quickstart
* Refactor _arrow_type function to remove max_length parameter
* Update Azure SQL Python quickstarts to clarify authentication methods and improve connection string examples
* Update mssql-python documentation links and improve quickstart examples
* Update Azure SQL Python quickstarts to improve clarity and consistency in authentication instructions
* Refactor authentication section headers for consistency and improve clarity in Python quickstart documentation
`ActiveDirectoryDefault` automatically discovers credentials from multiple sources without requiring interactive login. This is the **recommended option for local development**.
103
+
`ActiveDirectoryDefault` automatically discovers credentials from multiple sources without requiring interactive sign-in. This is the **recommended option for local development**.
104
104
105
105
For the most reliable local development experience, sign in with Azure CLI first:
In Windows, Microsoft Entra Interactive Authentication can use Microsoft Entra multifactor authentication technology to set up a connection. In this mode, an Azure Authentication dialog appears and lets you enter your credentials to complete the connection.
132
+
Microsoft Entra Interactive Authentication uses multifactor authentication technology to set up a connection. In this mode, an Azure Authentication dialog appears and lets you enter your credentials to complete the connection.
> On macOS, both `ActiveDirectoryInteractive` and `ActiveDirectoryDefault` work for Microsoft Entra authentication. `ActiveDirectoryInteractive` prompts you to sign in every time you run the script. To avoid repeated sign-in prompts, sign in once via the [Azure CLI](/cli/azure/install-azure-cli) by running `az login`, then use `ActiveDirectoryDefault`, which reuses the cached credential.
140
+
138
141
## [SQL Authentication](#tab/sql-auth)
139
142
140
143
You can authenticate directly to a SQL Server instance using a username and password.
In this quickstart, you use Python to connect to Azure SQL Database, Azure SQL Managed Instance, or Synapse SQL database and use T-SQL statements to query data.
@@ -107,16 +107,85 @@ You can use the PyPI command-line tool to verify that your intended packages are
107
107
108
108
1. In the current directory, create a new file named `.env`.
109
109
110
-
1. Within the `.env` file, add an entry for your connection string named `SQL_CONNECTION_STRING`. Replace the example here with your actual connection string value.
110
+
1. Within the `.env` file, add an entry for your connection string named `SQL_CONNECTION_STRING`. Replace the `<database-server-name>` and `<database-name>` placeholders with your own values.
111
+
112
+
The mssql-python driver has built-in support for Microsoft Entra authentication. Use the `Authentication` parameter to specify the authentication method.
`ActiveDirectoryDefault` automatically discovers credentials from multiple sources without requiring interactive login. This is the **recommended option for local development** and works on Windows, macOS, and Linux.
117
+
118
+
For the most reliable local development experience, sign in with Azure CLI first:
119
+
120
+
```bash
121
+
az login
122
+
```
123
+
124
+
Then use this connection string format in your `.env` file:
`ActiveDirectoryDefault` evaluates credentials in the following order:
131
+
1.**Environment variables** (for service principal credentials)
132
+
1.**Managed identity** (when running on Azure)
133
+
1.**Azure CLI** (from `az login`)
134
+
1.**Visual Studio** (Windows only)
135
+
1.**Azure PowerShell** (from `Connect-AzAccount`)
136
+
137
+
> [!TIP]
138
+
> For production applications, use the specific authentication method for your scenario to avoid credential discovery latency:
139
+
> -**Azure App Service/Functions**: Use `ActiveDirectoryMSI` (managed identity)
140
+
> -**Interactive user login**: Use `ActiveDirectoryInteractive`
141
+
> -**Service principal**: Use `ActiveDirectoryServicePrincipal`
142
+
143
+
### [Interactive Authentication](#tab/sql-inter)
144
+
145
+
Microsoft Entra Interactive Authentication uses multifactor authentication technology to set up a connection. In this mode, an Azure Authentication dialog appears and lets you enter your credentials to complete the connection.
> On macOS, both `ActiveDirectoryInteractive` and `ActiveDirectoryDefault` work for Microsoft Entra authentication. `ActiveDirectoryInteractive` prompts you to sign in every time you run the script. To avoid repeated sign-in prompts, log in once via the [Azure CLI](/cli/azure/install-azure-cli) by running `az login`, then use `ActiveDirectoryDefault`, which reuses the cached credential.
153
+
154
+
### [SQL Authentication](#tab/sql-auth)
155
+
156
+
You can authenticate directly to a SQL Server instance using a username and password.
> 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.
164
+
165
+
### [Fabric SQL Database](#tab/sql-fabric)
166
+
167
+
To connect to a [SQL database in Microsoft Fabric](/fabric/database/sql/overview), use the same authentication methods. The server name follows the Fabric format.
168
+
169
+
On **Windows domain-joined machines**, use `ActiveDirectoryIntegrated` for seamless authentication with no extra steps:
You can find your Fabric SQL database connection string in the Fabric portal under your database's settings.
182
+
183
+
---
184
+
116
185
> [!TIP]
117
-
> 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 [DSN and Connection String Keywords and Attributes](/sql/connect/odbc/dsn-connection-string-attribute).
186
+
> 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 [DSN and Connection String Keywords and Attributes](/sql/connect/odbc/dsn-connection-string-attribute).
118
187
119
-
1. In a text editor, create a new file named *sqltest.py*.
188
+
3. In a text editor, create a new file named *sqltest.py*.
0 commit comments