Skip to content

Commit b633b40

Browse files
committed
Merge branch 'main' into MergeShared-SqlConnectionPoolKey
2 parents 5f537d0 + c0fd7d2 commit b633b40

34 files changed

+2182
-9049
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public enum SqlAuthenticationMethod
172172
SqlPassword = 1
173173
}
174174
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml' path='docs/members[@name="SqlAuthenticationParameters"]/SqlAuthenticationParameters/*'/>
175-
public partial class SqlAuthenticationParameters
175+
public class SqlAuthenticationParameters
176176
{
177177
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml' path='docs/members[@name="SqlAuthenticationParameters"]/ctor/*'/>
178178
protected SqlAuthenticationParameters(Microsoft.Data.SqlClient.SqlAuthenticationMethod authenticationMethod, string serverName, string databaseName, string resource, string authority, string userId, string password, System.Guid connectionId, int connectionTimeout) { }

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlDataRecord.netcore.cs">
164164
<Link>Microsoft\Data\SqlClient\Server\SqlDataRecord.netcore.cs</Link>
165165
</Compile>
166+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs">
167+
<Link>Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs</Link>
168+
</Compile>
166169
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
167170
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
168171
</Compile>
@@ -205,6 +208,9 @@
205208
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnMapping.cs">
206209
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnMapping.cs</Link>
207210
</Compile>
211+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs">
212+
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs</Link>
213+
</Compile>
208214
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyOptions.cs">
209215
<Link>Microsoft\Data\SqlClient\SqlBulkCopyOptions.cs</Link>
210216
</Compile>
@@ -262,12 +268,24 @@
262268
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlDataAdapter.cs">
263269
<Link>Microsoft\Data\SqlClient\SqlDataAdapter.cs</Link>
264270
</Compile>
271+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlDependency.cs">
272+
<Link>Microsoft\Data\SqlClient\SqlDependency.cs</Link>
273+
</Compile>
274+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlEnums.cs">
275+
<Link>Microsoft\Data\SqlClient\SqlEnums.cs</Link>
276+
</Compile>
265277
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlErrorCollection.cs">
266278
<Link>Microsoft\Data\SqlClient\SqlErrorCollection.cs</Link>
267279
</Compile>
280+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlException.cs">
281+
<Link>Microsoft\Data\SqlClient\SqlException.cs</Link>
282+
</Compile>
268283
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs">
269284
<Link>Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs</Link>
270285
</Compile>
286+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlNotificationEventArgs.cs">
287+
<Link>Microsoft\Data\SqlClient\SqlNotificationEventArgs.cs</Link>
288+
</Compile>
271289
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlNotificationInfo.cs">
272290
<Link>Microsoft\Data\SqlClient\SqlNotificationInfo.cs</Link>
273291
</Compile>
@@ -286,6 +304,9 @@
286304
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlQueryMetadataCache.cs">
287305
<Link>Microsoft\Data\SqlClient\SqlQueryMetadataCache.cs</Link>
288306
</Compile>
307+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlReferenceCollection.cs">
308+
<Link>Microsoft\Data\SqlClient\SqlReferenceCollection.cs</Link>
309+
</Compile>
289310
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlRowUpdatedEvent.cs">
290311
<Link>Microsoft\Data\SqlClient\SqlRowUpdatedEvent.cs</Link>
291312
</Compile>
@@ -325,6 +346,9 @@
325346
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs">
326347
<Link>Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs</Link>
327348
</Compile>
349+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs">
350+
<Link>Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs</Link>
351+
</Compile>
328352
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SignatureVerificationCache.cs">
329353
<Link>Microsoft\Data\SqlClient\SignatureVerificationCache.cs</Link>
330354
</Compile>
@@ -485,9 +509,7 @@
485509
</EmbeddedResource>
486510
<Compile Include="Microsoft\Data\SqlClient\AAsyncCallContext.cs" />
487511
<Compile Include="Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs" />
488-
<Compile Include="Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs" />
489512
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
490-
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />
491513
<Compile Include="Microsoft\Data\SqlClient\SqlDbColumn.cs" />
492514
<Compile Include="Microsoft\Data\Common\DbConnectionOptions.cs" />
493515
<Compile Include="$(CommonPath)\Microsoft\Data\ProviderBase\DbConnectionInternal.cs">
@@ -522,7 +544,6 @@
522544
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
523545
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
524546
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
525-
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs" />
526547
<Compile Include="Microsoft\Data\SqlClient\SqlClientDiagnosticListenerExtensions.cs" />
527548
<Compile Include="Microsoft\Data\SqlClient\SqlClientFactory.cs" />
528549
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
@@ -535,25 +556,20 @@
535556
<Link>Microsoft\Data\SqlClient\SqlConnectionTimeoutErrorInternal.cs</Link>
536557
</Compile>
537558
<Compile Include="Microsoft\Data\SqlClient\SqlDataReader.cs" />
538-
<Compile Include="Microsoft\Data\SqlClient\SqlDependency.cs" />
539559
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyListener.cs" />
540560
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyUtils.cs" />
541561
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyUtils.AppDomain.cs" />
542562
<Compile Include="Microsoft\Data\SqlClient\SqlDelegatedTransaction.cs" />
543-
<Compile Include="Microsoft\Data\SqlClient\SqlEnums.cs" />
544563
<Compile Include="Microsoft\Data\SqlClient\SqlError.cs" />
545564
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlEnclaveSession.cs">
546565
<Link>Microsoft\Data\SqlClient\SqlEnclaveSession.cs</Link>
547566
</Compile>
548-
<Compile Include="Microsoft\Data\SqlClient\SqlException.cs" />
549567
<Compile Include="Microsoft\Data\SqlClient\SqlInfoMessageEvent.cs" />
550568
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnection.cs" />
551569
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs" />
552570
<Compile Include="Microsoft\Data\SqlClient\SqlInternalTransaction.cs" />
553571
<Compile Include="Microsoft\Data\SqlClient\SqlMetadataFactory.cs" />
554-
<Compile Include="Microsoft\Data\SqlClient\SqlNotificationEventArgs.cs" />
555572
<Compile Include="Microsoft\Data\SqlClient\SqlParameter.cs" />
556-
<Compile Include="Microsoft\Data\SqlClient\SqlReferenceCollection.cs" />
557573
<Compile Include="Microsoft\Data\SqlClient\SqlSequentialStream.cs" />
558574
<Compile Include="Microsoft\Data\SqlClient\SqlSequentialTextReader.cs" />
559575
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlStatistics.cs">

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,5 +346,160 @@ public static void WriteTransactionRollbackError(this SqlDiagnosticListener @thi
346346
});
347347
}
348348
}
349+
350+
public static DiagnosticScope CreateCommandScope(this SqlDiagnosticListener @this, SqlCommand command, SqlTransaction transaction, [CallerMemberName] string operationName = "")
351+
{
352+
return DiagnosticScope.CreateCommandScope(@this, command, transaction, operationName);
353+
}
354+
355+
public static DiagnosticTransactionScope CreateTransactionCommitScope(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operationName = "")
356+
{
357+
return DiagnosticTransactionScope.CreateTransactionCommitScope(@this, isolationLevel, connection, transaction, operationName);
358+
}
359+
360+
public static DiagnosticTransactionScope CreateTransactionRollbackScope(this SqlDiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName, [CallerMemberName] string operationName = "")
361+
{
362+
return DiagnosticTransactionScope.CreateTransactionRollbackScope(@this, isolationLevel, connection, transaction, transactionName, operationName);
363+
}
364+
}
365+
366+
internal ref struct DiagnosticScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching
367+
{
368+
private const int CommandOperation = 1;
369+
private const int ConnectionOpenOperation = 2;
370+
371+
private readonly SqlDiagnosticListener _diagnostics;
372+
private readonly int _operation;
373+
private readonly string _operationName;
374+
private readonly Guid _operationId;
375+
private readonly object _context1;
376+
private readonly object _context2;
377+
private Exception _exception;
378+
379+
private DiagnosticScope(SqlDiagnosticListener diagnostics, int operation, Guid operationsId, string operationName, object context1, object context2)
380+
{
381+
_diagnostics = diagnostics;
382+
_operation = operation;
383+
_operationId = operationsId;
384+
_operationName = operationName;
385+
_context1 = context1;
386+
_context2 = context2;
387+
_exception = null;
388+
}
389+
390+
public void Dispose()
391+
{
392+
switch (_operation)
393+
{
394+
case CommandOperation:
395+
if (_exception != null)
396+
{
397+
_diagnostics.WriteCommandError(_operationId, (SqlCommand)_context1, (SqlTransaction)_context2, _exception, _operationName);
398+
}
399+
else
400+
{
401+
_diagnostics.WriteCommandAfter(_operationId, (SqlCommand)_context1, (SqlTransaction)_context2, _operationName);
402+
}
403+
break;
404+
405+
case ConnectionOpenOperation:
406+
if (_exception != null)
407+
{
408+
_diagnostics.WriteConnectionOpenError(_operationId, (SqlConnection)_context1, _exception, _operationName);
409+
}
410+
else
411+
{
412+
_diagnostics.WriteConnectionOpenAfter(_operationId, (SqlConnection)_context1, _operationName);
413+
}
414+
break;
415+
416+
// ConnectionCloseOperation is not implemented because it is conditionally emitted and that requires manual calls to the write apis
417+
}
418+
}
419+
420+
public void SetException(Exception ex)
421+
{
422+
_exception = ex;
423+
}
424+
425+
public static DiagnosticScope CreateCommandScope(SqlDiagnosticListener diagnostics, SqlCommand command, SqlTransaction transaction, [CallerMemberName] string operationName = "")
426+
{
427+
Guid operationId = diagnostics.WriteCommandBefore(command, transaction, operationName);
428+
return new DiagnosticScope(diagnostics, CommandOperation, operationId, operationName, command, transaction);
429+
}
430+
}
431+
432+
internal ref struct DiagnosticTransactionScope //: IDisposable //ref structs cannot implement interfaces but the compiler will use pattern matching
433+
{
434+
public const int TransactionCommit = 1;
435+
public const int TransactionRollback = 2;
436+
437+
private readonly SqlDiagnosticListener _diagnostics;
438+
private readonly int _operation;
439+
private readonly Guid _operationId;
440+
private readonly string _operationName;
441+
private readonly IsolationLevel _isolationLevel;
442+
private readonly SqlConnection _connection;
443+
private readonly SqlInternalTransaction _transaction;
444+
private readonly string _transactionName;
445+
private Exception _exception;
446+
447+
public DiagnosticTransactionScope(SqlDiagnosticListener diagnostics, int operation, Guid operationId, string operationName, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName)
448+
{
449+
_diagnostics = diagnostics;
450+
_operation = operation;
451+
_operationId = operationId;
452+
_operationName = operationName;
453+
_isolationLevel = isolationLevel;
454+
_connection = connection;
455+
_transaction = transaction;
456+
_transactionName = transactionName;
457+
_exception = null;
458+
}
459+
460+
public void Dispose()
461+
{
462+
switch (_operation)
463+
{
464+
case TransactionCommit:
465+
if (_exception != null)
466+
{
467+
_diagnostics.WriteTransactionCommitError(_operationId, _isolationLevel, _connection, _transaction, _exception, _operationName);
468+
}
469+
else
470+
{
471+
_diagnostics.WriteTransactionCommitAfter(_operationId, _isolationLevel, _connection, _transaction, _operationName);
472+
}
473+
break;
474+
475+
case TransactionRollback:
476+
if (_exception != null)
477+
{
478+
_diagnostics.WriteTransactionRollbackError(_operationId, _isolationLevel, _connection, _transaction, _exception, _transactionName, _operationName);
479+
}
480+
else
481+
{
482+
_diagnostics.WriteTransactionRollbackAfter(_operationId, _isolationLevel, _connection, _transaction, _transactionName, _operationName);
483+
}
484+
break;
485+
}
486+
}
487+
488+
public void SetException(Exception ex)
489+
{
490+
_exception = ex;
491+
}
492+
493+
public static DiagnosticTransactionScope CreateTransactionCommitScope(SqlDiagnosticListener diagnostics, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operationName = "")
494+
{
495+
Guid operationId = diagnostics.WriteTransactionCommitBefore(isolationLevel, connection, transaction, operationName);
496+
return new DiagnosticTransactionScope(diagnostics, TransactionCommit, operationId, operationName, isolationLevel, connection, transaction, null);
497+
}
498+
499+
public static DiagnosticTransactionScope CreateTransactionRollbackScope(SqlDiagnosticListener diagnostics, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName, [CallerMemberName] string operationName = "")
500+
{
501+
Guid operationId = diagnostics.WriteTransactionRollbackBefore(isolationLevel, connection, transaction, transactionName, operationName);
502+
return new DiagnosticTransactionScope(diagnostics, TransactionCommit, operationId, operationName, isolationLevel, connection, transaction, transactionName);
503+
}
349504
}
350505
}

0 commit comments

Comments
 (0)