@@ -596,7 +596,7 @@ To configure this setup in your code, ensure your application registers separate
596
596
1. In your project, install the required packages. The Azure Identity library provides `DefaultAzureCredential`.
597
597
598
598
```bash
599
- npm install --save @azure/identity @azure/storage-blob @azure/cosmos mssql
599
+ npm install --save @azure/identity @azure/storage-blob @azure/cosmos tedious
600
600
```
601
601
602
602
1. Add the following to your code:
@@ -605,7 +605,7 @@ To configure this setup in your code, ensure your application registers separate
605
605
import { DefaultAzureCredential } from "@azure/identity";
606
606
import { BlobServiceClient } from "@azure/storage-blob";
607
607
import { CosmosClient } from "@azure/cosmos";
608
- import { sql } from "mssql ";
608
+ import { Connection } from "tedious ";
609
609
610
610
// Create a DefaultAzureCredential instance that configures the underlying
611
611
// ManagedIdentityCredential to use a user-assigned managed identity.
@@ -637,27 +637,23 @@ To configure this setup in your code, ensure your application registers separate
637
637
credential: credentialDatabases
638
638
});
639
639
640
- // Open a connection to Azure SQL using a managed identity with mssql package.
641
- // mssql reads the environment variables to get the managed identity.
642
- // The DefaultAzureCredential instance stored in the credentialDatabases variable can't be
643
- // used here, so sharing isn't possible between Cosmos DB and Azure SQL.
644
- const server = process.env.AZURE_SQL_SERVER;
645
- const database = process.env.AZURE_SQL_DATABASE;
646
- const port = parseInt(process.env.AZURE_SQL_PORT);
647
-
640
+ // Configure connection and connect to Azure SQL
648
641
const config = {
649
- server,
650
- port,
651
- database,
652
- authentication: {
653
- type: 'azure-active-directory-default'
654
- },
642
+ server: process.env.AZURE_SQL_SERVER,
643
+ authentication: {
644
+ type: 'azure-active-directory-access-token',
655
645
options: {
656
- encrypt: true
646
+ token: credentialDatabases.getToken("https://database.windows.net//.default").token
657
647
}
648
+ },
649
+ options: {
650
+ database: process.env.AZURE_SQL_DATABASE,
651
+ encrypt: true
652
+ }
658
653
};
659
654
660
- await sql.connect(sqlConfig);
655
+ const connection = new Connection(config);
656
+ connection.connect();
661
657
```
662
658
663
659
### [Python](#tab/python)
0 commit comments