Skip to content

Commit

Permalink
Rollup of feedback from Batch 1 PR
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardneal committed Sep 5, 2024
1 parent cf92a05 commit bb8006c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<value>1</value>
</AlwaysBlock>
<NeverBlock>
<summary>Blocking period OFF for Azure SQL servers, but ON for all other SQL servers.</summary>
<summary>Blocking period OFF for all SQL servers, including Azure SQL servers.</summary>
<value>2</value>
</NeverBlock>
</members>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<members name="SqlAuthenticationInitializer">
<SqlAuthenticationInitializer>
<summary>
Called from constructors in derived classes to initialize the <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationInitializer" /> class.
Called during instantiation of the first <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> instance.
</summary>
</SqlAuthenticationInitializer>
<ctor>
<summary>
Default Constructor to initialize the <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationInitializer" /> class.
Default constructor to instantiate the <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationInitializer" /> class.
</summary>
</ctor>
<Initialize>
<summary>
When overridden in a derived class, initializes the authentication initializer. This method is called by the <see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationInitializer.#ctor" /> constructor during startup.
When overridden in a derived class, initializes the authentication initializer. This method is called immediately after the <see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationInitializer.#ctor" /> constructor during instantiation of the first <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> instance.
</summary>
</Initialize>
</members>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<docs>
<members name="SqlAuthenticationMethod">
<SqlAuthenticationMethod>
<summary>Describes the different SQL authentication methods that can be used by a client connecting to Azure SQL Database. For details, see <see href="https://docs.microsoft.com/azure/sql-database/sql-database-aad-authentication">Connecting to SQL Database By Using Azure Active Directory Authentication</see>.</summary>
<summary>Describes the different SQL authentication methods that can be used by a client connecting to Azure SQL Database. For details, see <see href="https://learn.microsoft.com/azure/azure-sql/database/authentication-aad-overview">Use Microsoft Entra Authentication</see>.</summary>
</SqlAuthenticationMethod>
<NotSpecified>
<summary>The authentication method is not specified.</summary>
<value>0</value>
</NotSpecified>
<SqlPassword>
<summary>The authentication method is Sql Password.</summary>
<summary>The authentication method uses Sql Password. Use Sql Password to connect to a SQL Database using SQL Server authentication.</summary>
<value>1</value>
</SqlPassword>
<ActiveDirectoryPassword>
<summary>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.</summary>
<summary>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.</summary>
<value>2</value>
</ActiveDirectoryPassword>
<ActiveDirectoryIntegrated>
Expand Down
37 changes: 19 additions & 18 deletions doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,34 @@
{
public override async Task&lt;SqlAuthenticationToken&gt; 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()
Expand Down Expand Up @@ -87,16 +88,16 @@
</SetProvider>
<BeforeLoad>
<param name="authenticationMethod">The authentication method.</param>
<summary>This method is called immediately before the provider is added to SQL drivers registry.</summary>
<summary>This method is called immediately before the provider is added to SQL authentication provider registry.</summary>
<remarks>
Avoid performing long-waiting tasks in this method, since it can block other threads from accessing the provider registry.
</remarks>
</BeforeLoad>
<BeforeUnload>
<param name="authenticationMethod">The authentication method.</param>
<summary>This method is called immediately before the provider is removed from the SQL drivers registry.</summary>
<summary>This method is called immediately before the provider is removed from the SQL authentication provider registry.</summary>
<remarks>
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.
</remarks>
</BeforeUnload>
<IsSupported>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<docs>
<members name="SqlAuthenticationToken">
<SqlAuthenticationToken>
<summary>Represents an AD authentication token.</summary>
<summary>Represents an authentication token.</summary>
</SqlAuthenticationToken>
<ctor>
<param name="accessToken">The access token.</param>
Expand Down
12 changes: 3 additions & 9 deletions doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -163,9 +163,6 @@
batch.BatchCommands.Add(batchCommand);
}

// Optionally Prepare
batch.Prepare();

var results = new List&lt;int&gt;(count);
using (SqlDataReader reader = batch.ExecuteReader())
{
Expand All @@ -185,7 +182,7 @@
</BatchCommands>
<Commands>
<summary>
The list of commands contained in the batch in a <see cref="T:System.Collections.IList" /> of <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" /> objects.
The list of commands contained in the batch in a <see cref="T:System.Collections.Generic.List{Microsoft.Data.SqlClient.SqlBatchCommand}" />.
</summary>
</Commands>
<ExecuteReader>
Expand Down Expand Up @@ -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";
Expand All @@ -224,9 +221,6 @@
batch.BatchCommands.Add(batchCommand);
}

// Optionally Prepare
batch.Prepare();

var results = new List&lt;int&gt;(count);
using (SqlDataReader reader = batch.ExecuteReader())
{
Expand Down

0 comments on commit bb8006c

Please sign in to comment.