@@ -596,7 +596,7 @@ To configure this setup in your code, ensure your application registers separate
5965961. In your project, install the required packages. The Azure Identity library provides `DefaultAzureCredential`.
597597
598598 ```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
600600 ```
601601
6026021. Add the following to your code:
@@ -605,7 +605,7 @@ To configure this setup in your code, ensure your application registers separate
605605 import { DefaultAzureCredential } from "@azure/identity";
606606 import { BlobServiceClient } from "@azure/storage-blob";
607607 import { CosmosClient } from "@azure/cosmos";
608- import { sql } from "mssql ";
608+ import { Connection } from "tedious ";
609609
610610 // Create a DefaultAzureCredential instance that configures the underlying
611611 // ManagedIdentityCredential to use a user-assigned managed identity.
@@ -637,27 +637,23 @@ To configure this setup in your code, ensure your application registers separate
637637 credential: credentialDatabases
638638 });
639639
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
648641 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',
655645 options: {
656- encrypt: true
646+ token: credentialDatabases.getToken("https://database.windows.net//.default").token
657647 }
648+ },
649+ options: {
650+ database: process.env.AZURE_SQL_DATABASE,
651+ encrypt: true
652+ }
658653 };
659654
660- await sql.connect(sqlConfig);
655+ const connection = new Connection(config);
656+ connection.connect();
661657 ```
662658
663659### [Python](#tab/python)
0 commit comments