From bb8006c194e490c2024a6151b9b34e36114168d2 Mon Sep 17 00:00:00 2001
From: Edward Neal <55035479+edwardneal@users.noreply.github.com>
Date: Thu, 5 Sep 2024 21:31:37 +0100
Subject: [PATCH] Rollup of feedback from Batch 1 PR
---
.../PoolBlockingPeriod.xml | 2 +-
.../SqlAuthenticationInitializer.xml | 6 +--
.../SqlAuthenticationMethod.xml | 6 +--
.../SqlAuthenticationProvider.xml | 37 ++++++++++---------
.../SqlAuthenticationToken.xml | 2 +-
.../Microsoft.Data.SqlClient/SqlBatch.xml | 12 ++----
6 files changed, 30 insertions(+), 35 deletions(-)
diff --git a/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml
index 5f791173bc..acd15441e7 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml
@@ -13,7 +13,7 @@
1
- Blocking period OFF for Azure SQL servers, but ON for all other SQL servers.
+ Blocking period OFF for all SQL servers, including Azure SQL servers.
2
diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml
index b2ae7afbf2..ad1f80b905 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml
@@ -2,17 +2,17 @@
- Called from constructors in derived classes to initialize the class.
+ Called during instantiation of the first instance.
- Default Constructor to initialize the class.
+ Default constructor to instantiate the class.
- When overridden in a derived class, initializes the authentication initializer. This method is called by the constructor during startup.
+ When overridden in a derived class, initializes the authentication initializer. This method is called immediately after the constructor during instantiation of the first instance.
diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml
index 70b6c2e821..cd15a65ec2 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml
@@ -1,18 +1,18 @@
- Describes the different SQL authentication methods that can be used by a client connecting to Azure SQL Database. For details, see Connecting to SQL Database By Using Azure Active Directory Authentication.
+ Describes the different SQL authentication methods that can be used by a client connecting to Azure SQL Database. For details, see Use Microsoft Entra Authentication.
The authentication method is not specified.
0
- The authentication method is Sql Password.
+ The authentication method uses Sql Password. Use Sql Password to connect to a SQL Database using SQL Server authentication.
1
- The authentication method uses Active Directory Password. Use Active Directory Password to connect to a SQL Database using an Azure AD principal name and password.
+ The authentication method uses Active Directory Password. Use Active Directory Password to connect to a SQL Database using a Microsoft Entra principal name and password.
2
diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml
index 9b6b8699e6..0a6e76a6a4 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml
@@ -23,33 +23,34 @@
{
public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenticationParameters parameters)
{
- string clientId = "my-client-id";
- string clientName = "My Application Name";
- string s_defaultScopeSuffix = "/.default";
-
- string[] scopes = new string[] { parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix };
-
- IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId)
+ const string ClientId = "my-client-id";
+ const string ClientName = "My Application Name";
+ const string DefaultScopeSuffix = "/.default";
+
+ string[] scopes = [ parameters.Resource.EndsWith(DefaultScopeSuffix) ? parameters.Resource : parameters.Resource + DefaultScopeSuffix ];
+
+ IPublicClientApplication app = PublicClientApplicationBuilder.Create(ClientId)
.WithAuthority(parameters.Authority)
- .WithClientName(clientName)
+ .WithClientName(ClientName)
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
.Build();
-
- AuthenticationResult result = await app.AcquireTokenWithDeviceCode(scopes,
- deviceCodeResult => CustomDeviceFlowCallback(deviceCodeResult)).ExecuteAsync();
+ using CancellationTokenSource connectionTimeoutCancellation = new CancellationTokenSource(TimeSpan.FromSeconds(parameters.ConnectionTimeout));
+
+ AuthenticationResult result = await app.AcquireTokenWithDeviceCode(scopes, CustomDeviceFlowCallback)
+ .ExecuteAsync(connectionTimeoutCancellation.Token);
return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn);
}
-
+
public override bool IsSupported(SqlAuthenticationMethod authenticationMethod) =>
authenticationMethod.Equals(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow);
-
+
private Task CustomDeviceFlowCallback(DeviceCodeResult result)
{
Console.WriteLine(result.Message);
- return Task.FromResult(0);
+ return Task.CompletedTask;
}
}
-
+
public class Program
{
public static void Main()
@@ -87,16 +88,16 @@
The authentication method.
- This method is called immediately before the provider is added to SQL drivers registry.
+ This method is called immediately before the provider is added to SQL authentication provider registry.
Avoid performing long-waiting tasks in this method, since it can block other threads from accessing the provider registry.
The authentication method.
- This method is called immediately before the provider is removed from the SQL drivers registry.
+ This method is called immediately before the provider is removed from the SQL authentication provider registry.
- For example, this method is called when a different provider with the same authentication method overrides this provider in the SQL drivers registry. Avoid performing long-waiting task in this method, since it can block other threads from accessing the provider registry.
+ For example, this method is called when a different provider with the same authentication method overrides this provider in the SQL authentication provider registry. Avoid performing long-waiting task in this method, since it can block other threads from accessing the provider registry.
diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml
index 8e4efd0698..52f79dd535 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml
@@ -1,7 +1,7 @@
- Represents an AD authentication token.
+ Represents an authentication token.
The access token.
diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml
index e76631fe45..ebbd733a09 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml
@@ -152,7 +152,7 @@
using var connection = new SqlConnection(connString);
connection.Open();
- var batch = new SqlBatch(connection);
+ using var batch = new SqlBatch(connection);
const int count = 10;
const string parameterName = "parameter";
@@ -163,9 +163,6 @@
batch.BatchCommands.Add(batchCommand);
}
- // Optionally Prepare
- batch.Prepare();
-
var results = new List<int>(count);
using (SqlDataReader reader = batch.ExecuteReader())
{
@@ -185,7 +182,7 @@
- The list of commands contained in the batch in a of objects.
+ The list of commands contained in the batch in a .
@@ -213,7 +210,7 @@
using var connection = new SqlConnection(connString);
connection.Open();
- var batch = new SqlBatch(connection);
+ using var batch = new SqlBatch(connection);
const int count = 10;
const string parameterName = "parameter";
@@ -224,9 +221,6 @@
batch.BatchCommands.Add(batchCommand);
}
- // Optionally Prepare
- batch.Prepare();
-
var results = new List<int>(count);
using (SqlDataReader reader = batch.ExecuteReader())
{