Skip to content

Commit 887308b

Browse files
Fixes for Hotfix 2 Release v1.0 (#219)
* Fixes for Hotfix 2 Release for v1.0 - Fix issue with SqlCommand OnStatementCompleted not being triggered - Reverted API changes done unintentionally to maintain sync with System.Data.SqlClient - Fix Ref definitions for authentication keyword * Update test fact * Reflect review comments
1 parent 5b06cda commit 887308b

9 files changed

Lines changed: 62 additions & 19 deletions

File tree

src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ public SqlConnectionStringBuilder(string connectionString) { }
525525
public Microsoft.Data.SqlClient.ApplicationIntent ApplicationIntent { get { throw null; } set { } }
526526
public string ApplicationName { get { throw null; } set { } }
527527
public string AttachDBFilename { get { throw null; } set { } }
528+
public Microsoft.Data.SqlClient.SqlAuthenticationMethod Authentication { get { throw null; } set { } }
528529
public int ConnectRetryCount { get { throw null; } set { } }
529530
public int ConnectRetryInterval { get { throw null; } set { } }
530531
public int ConnectTimeout { get { throw null; } set { } }

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
1414
/// </summary>
1515
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
1616
{
17+
private static readonly string s_defaultScopeSuffix = "/.default";
1718
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;
1819

1920
/// <summary>
@@ -27,7 +28,8 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
2728
.WithClientVersion(Common.ADP.GetAssemblyVersion().ToString())
2829
.Build();
2930
AuthenticationResult result;
30-
string[] scopes = parameters.Scopes;
31+
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
32+
string[] scopes = new string[] { scope };
3133

3234
// Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?).
3335
// parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting.

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SqlAuthenticationParameters {
2020
/// <summary>
2121
/// Resource URI.
2222
/// </summary>
23-
public string[] Scopes { get; }
23+
public string Resource { get; }
2424

2525
/// <summary>
2626
/// Authority URI.
@@ -56,15 +56,15 @@ protected SqlAuthenticationParameters(
5656
SqlAuthenticationMethod authenticationMethod,
5757
string serverName,
5858
string databaseName,
59-
string[] scopes,
59+
string resource,
6060
string authority,
6161
string userId,
6262
string password,
6363
Guid connectionId) {
6464
AuthenticationMethod = authenticationMethod;
6565
ServerName = serverName;
6666
DatabaseName = databaseName;
67-
Scopes = scopes;
67+
Resource = resource;
6868
Authority = authority;
6969
UserId = userId;
7070
Password = password;
@@ -78,7 +78,7 @@ internal class Builder {
7878
private readonly SqlAuthenticationMethod _authenticationMethod;
7979
private readonly string _serverName;
8080
private readonly string _databaseName;
81-
private readonly string[] _scopes;
81+
private readonly string _resource;
8282
private readonly string _authority;
8383
private string _userId;
8484
private string _password;
@@ -93,7 +93,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder)
9393
authenticationMethod: builder._authenticationMethod,
9494
serverName: builder._serverName,
9595
databaseName: builder._databaseName,
96-
scopes: builder._scopes,
96+
resource: builder._resource,
9797
authority: builder._authority,
9898
userId: builder._userId,
9999
password: builder._password,
@@ -142,7 +142,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource,
142142
_authenticationMethod = authenticationMethod;
143143
_serverName = serverName;
144144
_databaseName = databaseName;
145-
_scopes = new string[] { resource + "/.default" };
145+
_resource = resource;
146146
_authority = authority;
147147
}
148148
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,11 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
27842784
cmd.InternalRecordsAffected = count;
27852785
}
27862786
}
2787+
// Skip the bogus DONE counts sent by the server
2788+
if (stateObj._receivedColMetaData || (curCmd != TdsEnums.SELECT))
2789+
{
2790+
cmd.OnStatementCompleted(count);
2791+
}
27872792
}
27882793

27892794
stateObj._receivedColMetaData = false;

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
1414
/// </summary>
1515
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
1616
{
17+
private static readonly string s_defaultScopeSuffix = "/.default";
1718
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;
1819
private readonly SqlClientLogger _logger = new SqlClientLogger();
1920

@@ -28,7 +29,8 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
2829
.WithClientVersion(Common.ADP.GetAssemblyVersion().ToString())
2930
.Build();
3031
AuthenticationResult result;
31-
string[] scopes = parameters.Scopes;
32+
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
33+
string[] scopes = new string[] { scope };
3234

3335
// Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?).
3436
// parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class SqlAuthenticationParameters {
2121
/// <summary>
2222
/// Resource URI.
2323
/// </summary>
24-
public string[] Scopes { get; }
24+
public string Resource { get; }
2525

2626
/// <summary>
2727
/// Authority URI.
@@ -57,15 +57,15 @@ protected SqlAuthenticationParameters(
5757
SqlAuthenticationMethod authenticationMethod,
5858
string serverName,
5959
string databaseName,
60-
string[] scopes,
60+
string resource,
6161
string authority,
6262
string userId,
6363
string password,
6464
Guid connectionId) {
6565
AuthenticationMethod = authenticationMethod;
6666
ServerName = serverName;
6767
DatabaseName = databaseName;
68-
Scopes = scopes;
68+
Resource = resource;
6969
Authority = authority;
7070
UserId = userId;
7171
Password = password;
@@ -79,7 +79,7 @@ internal class Builder {
7979
private readonly SqlAuthenticationMethod _authenticationMethod;
8080
private readonly string _serverName;
8181
private readonly string _databaseName;
82-
private readonly string[] _scopes;
82+
private readonly string _resource;
8383
private readonly string _authority;
8484
private string _userId;
8585
private string _password;
@@ -94,7 +94,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder)
9494
authenticationMethod: builder._authenticationMethod,
9595
serverName: builder._serverName,
9696
databaseName: builder._databaseName,
97-
scopes: builder._scopes,
97+
resource: builder._resource,
9898
authority: builder._authority,
9999
userId: builder._userId,
100100
password: builder._password,
@@ -143,7 +143,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource,
143143
_authenticationMethod = authenticationMethod;
144144
_serverName = serverName;
145145
_databaseName = databaseName;
146-
_scopes = new string[] { resource + "/.default" };
146+
_resource = resource;
147147
_authority = authority;
148148
}
149149
}

src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@
7272
<Compile Include="DDBasics\DDMARSTest\DDMARSTest.cs" />
7373
<Compile Include="ProviderAgnostic\MultipleResultsTest\MultipleResultsTest.cs" />
7474
<Compile Include="ProviderAgnostic\ReaderTest\ReaderTest.cs" />
75-
<Compile Include="SQL\AsyncTest\AsyncTest.cs" />
76-
<Compile Include="SQL\CommandCancelTest\CommandCancelTest.cs" />
75+
<Compile Include="SQL\AsyncTest\AsyncTest.cs" />
76+
<Compile Include="SQL\SqlCommand\SqlCommandCompletedTest.cs" />
77+
<Compile Include="SQL\SqlCommand\SqlCommandCancelTest.cs" />
7778
<Compile Include="SQL\ConnectionPoolTest\ConnectionPoolTest.cs" />
7879
<Compile Include="SQL\ConnectivityTests\ConnectivityTest.cs" />
7980
<Compile Include="SQL\DataBaseSchemaTest\ConnectionSchemaTest.cs" />

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/CommandCancelTest/CommandCancelTest.cs renamed to src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlCommand/SqlCommandCancelTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
1212
{
13-
public static class CommandCancelTest
13+
public static class SqlCommandCancelTest
1414
{
1515
// Shrink the packet size - this should make timeouts more likely
1616
private static readonly string s_connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { PacketSize = 512 }).ConnectionString;
@@ -138,8 +138,8 @@ private static void MultiThreadedCancel(string constr, bool async)
138138
tasks[1].Start();
139139

140140
Task.WaitAll(tasks, 15 * 1000);
141-
142-
CommandCancelTest.VerifyConnection(command);
141+
142+
SqlCommandCancelTest.VerifyConnection(command);
143143
}
144144
}
145145

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Data;
2+
using Xunit;
3+
4+
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
5+
{
6+
public static class SqlCommandCompletedTest
7+
{
8+
private static readonly string s_connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { PacketSize = 512 }).ConnectionString;
9+
private static bool completedHandlerExecuted = false;
10+
11+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
12+
public static void VerifyStatmentCompletedCalled()
13+
{
14+
using (var conn = new SqlConnection(s_connStr))
15+
{
16+
using (var cmd = conn.CreateCommand())
17+
{
18+
cmd.CommandText = "SELECT COUNT(*) FROM sys.databases";
19+
cmd.StatementCompleted += StatementCompletedHandler;
20+
conn.Open();
21+
var res = cmd.ExecuteScalar();
22+
}
23+
}
24+
Assert.True(completedHandlerExecuted);
25+
}
26+
27+
private static void StatementCompletedHandler(object sender, StatementCompletedEventArgs args)
28+
{
29+
completedHandlerExecuted = true;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)