forked from dotnet/SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlUtil.cs
2468 lines (2223 loc) · 114 KB
/
SqlUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SysTx = System.Transactions;
[assembly: InternalsVisibleTo("FunctionalTests")]
namespace Microsoft.Data.SqlClient
{
using Microsoft.Data.Common;
static internal class AsyncHelper
{
internal static Task CreateContinuationTask(Task task, Action onSuccess, SqlInternalConnectionTds connectionToDoom = null, Action<Exception> onFailure = null)
{
if (task == null)
{
onSuccess();
return null;
}
else
{
TaskCompletionSource<object> completion = new TaskCompletionSource<object>();
ContinueTask(task, completion,
() => { onSuccess(); completion.SetResult(null); },
connectionToDoom, onFailure);
return completion.Task;
}
}
internal static Task CreateContinuationTask<T1, T2>(Task task, Action<T1, T2> onSuccess, T1 arg1, T2 arg2, SqlInternalConnectionTds connectionToDoom = null, Action<Exception> onFailure = null)
{
return CreateContinuationTask(task, () => onSuccess(arg1, arg2), connectionToDoom, onFailure);
}
internal static void ContinueTask(Task task,
TaskCompletionSource<object> completion,
Action onSuccess,
SqlInternalConnectionTds connectionToDoom = null,
Action<Exception> onFailure = null,
Action onCancellation = null,
Func<Exception, Exception> exceptionConverter = null,
SqlConnection connectionToAbort = null
)
{
Debug.Assert((connectionToAbort == null) || (connectionToDoom == null), "Should not specify both connectionToDoom and connectionToAbort");
task.ContinueWith(
tsk =>
{
if (tsk.Exception != null)
{
Exception exc = tsk.Exception.InnerException;
if (exceptionConverter != null)
{
exc = exceptionConverter(exc);
}
try
{
if (onFailure != null)
{
onFailure(exc);
}
}
finally
{
completion.TrySetException(exc);
}
}
else if (tsk.IsCanceled)
{
try
{
if (onCancellation != null)
{
onCancellation();
}
}
finally
{
completion.TrySetCanceled();
}
}
else
{
if (connectionToDoom != null || connectionToAbort != null)
{
RuntimeHelpers.PrepareConstrainedRegions();
try
{
#if DEBUG
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();
RuntimeHelpers.PrepareConstrainedRegions();
try {
tdsReliabilitySection.Start();
#endif //DEBUG
onSuccess();
#if DEBUG
}
finally {
tdsReliabilitySection.Stop();
}
#endif //DEBUG
}
catch (System.OutOfMemoryException e)
{
if (connectionToDoom != null)
{
connectionToDoom.DoomThisConnection();
}
else
{
connectionToAbort.Abort(e);
}
completion.SetException(e);
throw;
}
catch (System.StackOverflowException e)
{
if (connectionToDoom != null)
{
connectionToDoom.DoomThisConnection();
}
else
{
connectionToAbort.Abort(e);
}
completion.SetException(e);
throw;
}
catch (System.Threading.ThreadAbortException e)
{
if (connectionToDoom != null)
{
connectionToDoom.DoomThisConnection();
}
else
{
connectionToAbort.Abort(e);
}
completion.SetException(e);
throw;
}
catch (Exception e)
{
completion.SetException(e);
}
}
else
{ // no connection to doom - reliability section not required
try
{
onSuccess();
}
catch (Exception e)
{
completion.SetException(e);
}
}
}
}, TaskScheduler.Default
);
}
internal static void WaitForCompletion(Task task, int timeout, Action onTimeout = null, bool rethrowExceptions = true)
{
try
{
task.Wait(timeout > 0 ? (1000 * timeout) : Timeout.Infinite);
}
catch (AggregateException ae)
{
if (rethrowExceptions)
{
Debug.Assert(ae.InnerExceptions.Count == 1, "There is more than one exception in AggregateException");
ExceptionDispatchInfo.Capture(ae.InnerException).Throw();
}
}
if (!task.IsCompleted)
{
task.ContinueWith(t => { var ignored = t.Exception; }); //Ensure the task does not leave an unobserved exception
if (onTimeout != null)
{
onTimeout();
}
}
}
internal static void SetTimeoutException(TaskCompletionSource<object> completion, int timeout, Func<Exception> exc, CancellationToken ctoken)
{
if (timeout > 0)
{
Task.Delay(timeout * 1000, ctoken).ContinueWith((tsk) =>
{
if (!tsk.IsCanceled && !completion.Task.IsCompleted)
{
completion.TrySetException(exc());
}
});
}
}
}
sealed internal class InOutOfProcHelper
{
private static readonly InOutOfProcHelper SingletonInstance = new InOutOfProcHelper();
private bool _inProc = false;
// InOutOfProcHelper detects whether it's running inside the server or not. It does this
// by checking for the existence of a well-known function export on the current process.
// Note that calling conventions, etc. do not matter -- we'll never call the function, so
// only the name match or lack thereof matter.
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
private InOutOfProcHelper()
{
// Don't need to close this handle...
// SxS: we use this method to check if we are running inside the SQL Server process. This call should be safe in SxS environment.
IntPtr handle = SafeNativeMethods.GetModuleHandle(null);
if (IntPtr.Zero != handle)
{
// SQLBU 359301: Currently, the server exports different names for x86 vs. AMD64 and IA64. Supporting both names
// for now gives the server time to unify names across platforms without breaking currently-working ones.
// We can remove the obsolete name once the server is changed.
if (IntPtr.Zero != SafeNativeMethods.GetProcAddress(handle, "_______SQL______Process______Available@0"))
{
_inProc = true;
}
else if (IntPtr.Zero != SafeNativeMethods.GetProcAddress(handle, "______SQL______Process______Available"))
{
_inProc = true;
}
}
}
internal static bool InProc
{
get
{
return SingletonInstance._inProc;
}
}
}
static internal class SQL
{
// The class SQL defines the exceptions that are specific to the SQL Adapter.
// The class contains functions that take the proper informational variables and then construct
// the appropriate exception with an error string obtained from the resource Framework.txt.
// The exception is then returned to the caller, so that the caller may then throw from its
// location so that the catcher of the exception will have the appropriate call stack.
// This class is used so that there will be compile time checking of error
// messages. The resource Framework.txt will ensure proper string text based on the appropriate
// locale.
//
// SQL specific exceptions
//
//
// SQL.Connection
//
static internal Exception CannotGetDTCAddress()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_CannotGetDTCAddress));
}
static internal Exception InvalidOptionLength(string key)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidOptionLength, key));
}
static internal Exception InvalidInternalPacketSize(string str)
{
return ADP.ArgumentOutOfRange(str);
}
static internal Exception InvalidPacketSize()
{
return ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQL_InvalidTDSPacketSize));
}
static internal Exception InvalidPacketSizeValue()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidPacketSizeValue));
}
static internal Exception InvalidSSPIPacketSize()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidSSPIPacketSize));
}
static internal Exception NullEmptyTransactionName()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_NullEmptyTransactionName));
}
static internal Exception SnapshotNotSupported(System.Data.IsolationLevel level)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_SnapshotNotSupported, typeof(IsolationLevel), level.ToString()));
}
static internal Exception UserInstanceFailoverNotCompatible()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_UserInstanceFailoverNotCompatible));
}
static internal Exception CredentialsNotProvided(SqlAuthenticationMethod auth)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_CredentialsNotProvided, DbConnectionStringBuilderUtil.AuthenticationTypeToString(auth)));
}
static internal Exception InvalidCertAuth()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_Certificate));
}
static internal Exception AuthenticationAndIntegratedSecurity()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_AuthenticationAndIntegratedSecurity));
}
static internal Exception IntegratedWithUserIDAndPassword()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_IntegratedWithUserIDAndPassword));
}
static internal Exception InteractiveWithPassword()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InteractiveWithPassword));
}
static internal Exception DeviceFlowWithUsernamePassword()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_DeviceFlowWithUsernamePassword));
}
static internal Exception ManagedIdentityWithPassword(string authenticationMode)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_ManagedIdentityWithPassword, authenticationMode));
}
static internal Exception SettingIntegratedWithCredential()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingIntegratedWithCredential));
}
static internal Exception SettingInteractiveWithCredential()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingInteractiveWithCredential));
}
static internal Exception SettingDeviceFlowWithCredential()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingDeviceFlowWithCredential));
}
static internal Exception SettingManagedIdentityWithCredential(string authenticationMode)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingManagedIdentityWithCredential, authenticationMode));
}
static internal Exception SettingCredentialWithIntegratedArgument()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_SettingCredentialWithIntegrated));
}
static internal Exception SettingCredentialWithInteractiveArgument()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_SettingCredentialWithInteractive));
}
static internal Exception SettingCredentialWithDeviceFlowArgument()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_SettingCredentialWithDeviceFlow));
}
static internal Exception SettingCredentialWithManagedIdentityArgument(string authenticationMode)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_SettingCredentialWithManagedIdentity, authenticationMode));
}
static internal Exception SettingCredentialWithIntegratedInvalid()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingCredentialWithIntegrated));
}
static internal Exception SettingCredentialWithInteractiveInvalid()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingCredentialWithInteractive));
}
static internal Exception SettingCredentialWithDeviceFlowInvalid()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingCredentialWithDeviceFlow));
}
static internal Exception SettingCredentialWithManagedIdentityInvalid(string authenticationMode)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SettingCredentialWithManagedIdentity, authenticationMode));
}
static internal Exception InvalidSQLServerVersionUnknown()
{
return ADP.DataAdapter(StringsHelper.GetString(Strings.SQL_InvalidSQLServerVersionUnknown));
}
static internal Exception SynchronousCallMayNotPend()
{
return new Exception(StringsHelper.GetString(Strings.Sql_InternalError));
}
static internal Exception ConnectionLockedForBcpEvent()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ConnectionLockedForBcpEvent));
}
static internal Exception AsyncConnectionRequired()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_AsyncConnectionRequired));
}
static internal Exception FatalTimeout()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_FatalTimeout));
}
static internal Exception InstanceFailure()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_InstanceFailure));
}
static internal Exception ChangePasswordArgumentMissing(string argumentName)
{
return ADP.ArgumentNull(StringsHelper.GetString(Strings.SQL_ChangePasswordArgumentMissing, argumentName));
}
static internal Exception ChangePasswordConflictsWithSSPI()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_ChangePasswordConflictsWithSSPI));
}
static internal Exception ChangePasswordRequiresYukon()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ChangePasswordRequiresYukon));
}
static internal Exception UnknownSysTxIsolationLevel(SysTx.IsolationLevel isolationLevel)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_UnknownSysTxIsolationLevel, isolationLevel.ToString()));
}
static internal Exception ChangePasswordUseOfUnallowedKey(string key)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ChangePasswordUseOfUnallowedKey, key));
}
static internal Exception InvalidPartnerConfiguration(string server, string database)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_InvalidPartnerConfiguration, server, database));
}
static internal Exception BatchedUpdateColumnEncryptionSettingMismatch()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.TCE_BatchedUpdateColumnEncryptionSettingMismatch, "SqlCommandColumnEncryptionSetting", "SelectCommand", "InsertCommand", "UpdateCommand", "DeleteCommand"));
}
static internal Exception MARSUnsupportedOnConnection()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_MarsUnsupportedOnConnection));
}
static internal Exception CannotModifyPropertyAsyncOperationInProgress(string property)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_CannotModifyPropertyAsyncOperationInProgress, property));
}
static internal Exception NonLocalSSEInstance()
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_NonLocalSSEInstance));
}
// SQL.ActiveDirectoryAuth
//
static internal Exception UnsupportedAuthentication(string authentication)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_UnsupportedAuthentication, authentication));
}
static internal Exception UnsupportedSqlAuthenticationMethod(SqlAuthenticationMethod authentication)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_UnsupportedSqlAuthenticationMethod, authentication));
}
static internal Exception UnsupportedAuthenticationSpecified(SqlAuthenticationMethod authentication)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_UnsupportedAuthenticationSpecified, authentication));
}
static internal Exception CannotCreateAuthProvider(string authentication, string type, Exception e)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotCreateAuthProvider, authentication, type), e);
}
static internal Exception CannotCreateSqlAuthInitializer(string type, Exception e)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotCreateAuthInitializer, type), e);
}
static internal Exception CannotInitializeAuthProvider(string type, Exception e)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_CannotInitializeAuthProvider, type), e);
}
static internal Exception UnsupportedAuthenticationByProvider(string authentication, string type)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_UnsupportedAuthenticationByProvider, type, authentication));
}
static internal Exception CannotFindAuthProvider(string authentication)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindAuthProvider, authentication));
}
static internal Exception CannotGetAuthProviderConfig(Exception e)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_CannotGetAuthProviderConfig), e);
}
static internal Exception ParameterCannotBeEmpty(string paramName)
{
return ADP.ArgumentNull(StringsHelper.GetString(Strings.SQL_ParameterCannotBeEmpty, paramName));
}
static internal Exception ActiveDirectoryInteractiveTimeout()
{
return ADP.TimeoutException(Strings.SQL_Timeout_Active_Directory_Interactive_Authentication);
}
static internal Exception ActiveDirectoryDeviceFlowTimeout()
{
return ADP.TimeoutException(Strings.SQL_Timeout_Active_Directory_DeviceFlow_Authentication);
}
//
// SQL.DataCommand
//
static internal Exception NotificationsRequireYukon()
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SQL_NotificationsRequireYukon));
}
static internal ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, int value)
{
return ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQL_NotSupportedEnumerationValue, type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name);
}
static internal ArgumentOutOfRangeException NotSupportedCommandType(CommandType value)
{
#if DEBUG
switch(value) {
case CommandType.Text:
case CommandType.StoredProcedure:
Debug.Fail("valid CommandType " + value.ToString());
break;
case CommandType.TableDirect:
break;
default:
Debug.Fail("invalid CommandType " + value.ToString());
break;
}
#endif
return NotSupportedEnumerationValue(typeof(CommandType), (int)value);
}
static internal ArgumentOutOfRangeException NotSupportedIsolationLevel(IsolationLevel value)
{
#if DEBUG
switch(value) {
case IsolationLevel.Unspecified:
case IsolationLevel.ReadCommitted:
case IsolationLevel.ReadUncommitted:
case IsolationLevel.RepeatableRead:
case IsolationLevel.Serializable:
case IsolationLevel.Snapshot:
Debug.Fail("valid IsolationLevel " + value.ToString());
break;
case IsolationLevel.Chaos:
break;
default:
Debug.Fail("invalid IsolationLevel " + value.ToString());
break;
}
#endif
return NotSupportedEnumerationValue(typeof(IsolationLevel), (int)value);
}
static internal Exception OperationCancelled()
{
Exception exception = ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_OperationCancelled));
return exception;
}
static internal Exception PendingBeginXXXExists()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_PendingBeginXXXExists));
}
static internal ArgumentOutOfRangeException InvalidSqlDependencyTimeout(string param)
{
return ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SqlDependency_InvalidTimeout), param);
}
static internal Exception NonXmlResult()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_NonXmlResult));
}
//
// SQL.DataParameter
//
static internal Exception InvalidUdt3PartNameFormat()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidUdt3PartNameFormat));
}
static internal Exception InvalidParameterTypeNameFormat()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidParameterTypeNameFormat));
}
static internal Exception InvalidParameterNameLength(string value)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InvalidParameterNameLength, value));
}
static internal Exception PrecisionValueOutOfRange(byte precision)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_PrecisionValueOutOfRange, precision.ToString(CultureInfo.InvariantCulture)));
}
static internal Exception ScaleValueOutOfRange(byte scale)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_ScaleValueOutOfRange, scale.ToString(CultureInfo.InvariantCulture)));
}
static internal Exception TimeScaleValueOutOfRange(byte scale)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_TimeScaleValueOutOfRange, scale.ToString(CultureInfo.InvariantCulture)));
}
static internal Exception InvalidSqlDbType(SqlDbType value)
{
return ADP.InvalidEnumerationValue(typeof(SqlDbType), (int)value);
}
static internal Exception UnsupportedTVPOutputParameter(ParameterDirection direction, string paramName)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SqlParameter_UnsupportedTVPOutputParameter,
direction.ToString(), paramName));
}
static internal Exception DBNullNotSupportedForTVPValues(string paramName)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SqlParameter_DBNullNotSupportedForTVP, paramName));
}
static internal Exception InvalidTableDerivedPrecisionForTvp(string columnName, byte precision)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlParameter_InvalidTableDerivedPrecisionForTvp, precision, columnName, System.Data.SqlTypes.SqlDecimal.MaxPrecision));
}
static internal Exception UnexpectedTypeNameForNonStructParams(string paramName)
{
return ADP.NotSupported(StringsHelper.GetString(Strings.SqlParameter_UnexpectedTypeNameForNonStruct, paramName));
}
static internal Exception SingleValuedStructNotSupported()
{
return ADP.NotSupported(StringsHelper.GetString(Strings.MetaType_SingleValuedStructNotSupported));
}
static internal Exception ParameterInvalidVariant(string paramName)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParameterInvalidVariant, paramName));
}
static internal Exception MustSetTypeNameForParam(string paramType, string paramName)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_ParameterTypeNameRequired, paramType, paramName));
}
static internal Exception NullSchemaTableDataTypeNotSupported(string columnName)
{
return ADP.Argument(StringsHelper.GetString(Strings.NullSchemaTableDataTypeNotSupported, columnName));
}
static internal Exception InvalidSchemaTableOrdinals()
{
return ADP.Argument(StringsHelper.GetString(Strings.InvalidSchemaTableOrdinals));
}
static internal Exception EnumeratedRecordMetaDataChanged(string fieldName, int recordNumber)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_EnumeratedRecordMetaDataChanged, fieldName, recordNumber));
}
static internal Exception EnumeratedRecordFieldCountChanged(int recordNumber)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_EnumeratedRecordFieldCountChanged, recordNumber));
}
//
// SQL.SqlDataAdapter
//
//
// SQL.TDSParser
//
static internal Exception InvalidTDSVersion()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_InvalidTDSVersion));
}
static internal Exception ParsingError(ParsingErrorState state)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorWithState, ((int)state).ToString(CultureInfo.InvariantCulture)));
}
static internal Exception ParsingError(ParsingErrorState state, Exception innerException)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorWithState, ((int)state).ToString(CultureInfo.InvariantCulture)), innerException);
}
static internal Exception ParsingErrorValue(ParsingErrorState state, int value)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorValue, ((int)state).ToString(CultureInfo.InvariantCulture), value));
}
static internal Exception ParsingErrorOffset(ParsingErrorState state, int offset)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorOffset, ((int)state).ToString(CultureInfo.InvariantCulture), offset));
}
static internal Exception ParsingErrorFeatureId(ParsingErrorState state, int featureId)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorFeatureId, ((int)state).ToString(CultureInfo.InvariantCulture), featureId));
}
static internal Exception ParsingErrorToken(ParsingErrorState state, int token)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorToken, ((int)state).ToString(CultureInfo.InvariantCulture), token));
}
static internal Exception ParsingErrorLength(ParsingErrorState state, int length)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorLength, ((int)state).ToString(CultureInfo.InvariantCulture), length));
}
static internal Exception ParsingErrorStatus(ParsingErrorState state, int status)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorStatus, ((int)state).ToString(CultureInfo.InvariantCulture), status));
}
static internal Exception ParsingErrorLibraryType(ParsingErrorState state, int libraryType)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_ParsingErrorAuthLibraryType, ((int)state).ToString(CultureInfo.InvariantCulture), libraryType));
}
static internal Exception MoneyOverflow(string moneyValue)
{
return ADP.Overflow(StringsHelper.GetString(Strings.SQL_MoneyOverflow, moneyValue));
}
static internal Exception SmallDateTimeOverflow(string datetime)
{
return ADP.Overflow(StringsHelper.GetString(Strings.SQL_SmallDateTimeOverflow, datetime));
}
static internal Exception SNIPacketAllocationFailure()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SNIPacketAllocationFailure));
}
static internal Exception TimeOverflow(string time)
{
return ADP.Overflow(StringsHelper.GetString(Strings.SQL_TimeOverflow, time));
}
static internal Exception InvalidServerCertificate()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_InvalidServerCertificate));
}
//
// SQL.SqlDataReader
//
static internal Exception InvalidRead()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_InvalidRead));
}
static internal Exception NonBlobColumn(string columnName)
{
return ADP.InvalidCast(StringsHelper.GetString(Strings.SQL_NonBlobColumn, columnName));
}
static internal Exception NonCharColumn(string columnName)
{
return ADP.InvalidCast(StringsHelper.GetString(Strings.SQL_NonCharColumn, columnName));
}
static internal Exception StreamNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(StringsHelper.GetString(Strings.SQL_StreamNotSupportOnColumnType, columnName));
}
static internal Exception StreamNotSupportOnEncryptedColumn(string columnName)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.TCE_StreamNotSupportOnEncryptedColumn, columnName, "Stream"));
}
static internal Exception SequentialAccessNotSupportedOnEncryptedColumn(string columnName)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.TCE_SequentialAccessNotSupportedOnEncryptedColumn, columnName, "CommandBehavior=SequentialAccess"));
}
static internal Exception TextReaderNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(StringsHelper.GetString(Strings.SQL_TextReaderNotSupportOnColumnType, columnName));
}
static internal Exception XmlReaderNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(StringsHelper.GetString(Strings.SQL_XmlReaderNotSupportOnColumnType, columnName));
}
static internal Exception UDTUnexpectedResult(string exceptionText)
{
return ADP.TypeLoad(StringsHelper.GetString(Strings.SQLUDT_Unexpected, exceptionText));
}
//
// SQL.SqlDelegatedTransaction
//
static internal Exception CannotCompleteDelegatedTransactionWithOpenResults(SqlInternalConnectionTds internalConnection, bool marsOn)
{
SqlErrorCollection errors = new SqlErrorCollection();
errors.Add(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, null, (StringsHelper.GetString(Strings.ADP_OpenReaderExists, marsOn ? ADP.Command : ADP.Connection)), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
return SqlException.CreateException(errors, null, internalConnection);
}
static internal SysTx.TransactionPromotionException PromotionFailed(Exception inner)
{
SysTx.TransactionPromotionException e = new SysTx.TransactionPromotionException(StringsHelper.GetString(Strings.SqlDelegatedTransaction_PromotionFailed), inner);
ADP.TraceExceptionAsReturnValue(e);
return e;
}
//
// SQL.SqlDependency
//
static internal Exception SqlCommandHasExistingSqlNotificationRequest()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQLNotify_AlreadyHasCommand));
}
static internal Exception SqlDepCannotBeCreatedInProc()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlNotify_SqlDepCannotBeCreatedInProc));
}
static internal Exception SqlDepDefaultOptionsButNoStart()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_DefaultOptionsButNoStart));
}
static internal Exception SqlDependencyDatabaseBrokerDisabled()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_DatabaseBrokerDisabled));
}
static internal Exception SqlDependencyEventNoDuplicate()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_EventNoDuplicate));
}
static internal Exception SqlDependencyDuplicateStart()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_DuplicateStart));
}
static internal Exception SqlDependencyIdMismatch()
{
// do not include the id because it may require SecurityPermission(Infrastructure) permission
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_IdMismatch));
}
static internal Exception SqlDependencyNoMatchingServerStart()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_NoMatchingServerStart));
}
static internal Exception SqlDependencyNoMatchingServerDatabaseStart()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlDependency_NoMatchingServerDatabaseStart));
}
static internal Exception SqlNotificationException(SqlNotificationEventArgs notify)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQLNotify_ErrorFormat, notify.Type, notify.Info, notify.Source));
}
//
// SQL.SqlMetaData
//
static internal Exception SqlMetaDataNoMetaData()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlMetaData_NoMetadata));
}
static internal Exception MustSetUdtTypeNameForUdtParams()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_InvalidUdtTypeName));
}
static internal Exception UnexpectedUdtTypeNameForNonUdtParams()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_UnexpectedUdtTypeName));
}
static internal Exception UDTInvalidSqlType(string typeName)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_InvalidSqlType, typeName));
}
static internal Exception UDTInvalidSize(int maxSize, int maxSupportedSize)
{
throw ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQLUDT_InvalidSize, maxSize, maxSupportedSize));
}
static internal Exception InvalidSqlDbTypeForConstructor(SqlDbType type)
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlMetaData_InvalidSqlDbTypeForConstructorFormat, type.ToString()));
}
static internal Exception NameTooLong(string parameterName)
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlMetaData_NameTooLong), parameterName);
}
static internal Exception InvalidSortOrder(SortOrder order)
{
return ADP.InvalidEnumerationValue(typeof(SortOrder), (int)order);
}
static internal Exception MustSpecifyBothSortOrderAndOrdinal(SortOrder order, int ordinal)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlMetaData_SpecifyBothSortOrderAndOrdinal, order.ToString(), ordinal));
}
static internal Exception TableTypeCanOnlyBeParameter()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQLTVP_TableTypeCanOnlyBeParameter));
}
static internal Exception UnsupportedColumnTypeForSqlProvider(string columnName, string typeName)
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlProvider_InvalidDataColumnType, columnName, typeName));
}
static internal Exception InvalidColumnMaxLength(string columnName, long maxLength)
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlProvider_InvalidDataColumnMaxLength, columnName, maxLength));
}
static internal Exception InvalidColumnPrecScale()
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlMisc_InvalidPrecScaleMessage));
}
static internal Exception NotEnoughColumnsInStructuredType()
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlProvider_NotEnoughColumnsInStructuredType));
}
static internal Exception DuplicateSortOrdinal(int sortOrdinal)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlProvider_DuplicateSortOrdinal, sortOrdinal));
}
static internal Exception MissingSortOrdinal(int sortOrdinal)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlProvider_MissingSortOrdinal, sortOrdinal));
}
static internal Exception SortOrdinalGreaterThanFieldCount(int columnOrdinal, int sortOrdinal)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlProvider_SortOrdinalGreaterThanFieldCount, sortOrdinal, columnOrdinal));
}
static internal Exception IEnumerableOfSqlDataRecordHasNoRows()
{
return ADP.Argument(StringsHelper.GetString(Strings.IEnumerableOfSqlDataRecordHasNoRows));
}
//
// SqlPipe
//
static internal Exception SqlPipeCommandHookedUpToNonContextConnection()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlPipe_CommandHookedUpToNonContextConnection));
}
static internal Exception SqlPipeMessageTooLong(int messageLength)
{
return ADP.Argument(StringsHelper.GetString(Strings.SqlPipe_MessageTooLong, messageLength));
}
static internal Exception SqlPipeIsBusy()
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlPipe_IsBusy));
}
static internal Exception SqlPipeAlreadyHasAnOpenResultSet(string methodName)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlPipe_AlreadyHasAnOpenResultSet, methodName));
}
static internal Exception SqlPipeDoesNotHaveAnOpenResultSet(string methodName)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SqlPipe_DoesNotHaveAnOpenResultSet, methodName));
}
//
// : ISqlResultSet
//
static internal Exception SqlResultSetClosed(string methodname)
{
if (methodname == null)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SqlResultSetClosed2));
}
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SqlResultSetClosed, methodname));
}
static internal Exception SqlResultSetNoData(string methodname)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.ADP_DataReaderNoData, methodname));
}
static internal Exception SqlRecordReadOnly(string methodname)
{
if (methodname == null)
{
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SqlRecordReadOnly2));
}
return ADP.InvalidOperation(StringsHelper.GetString(Strings.SQL_SqlRecordReadOnly, methodname));
}
static internal Exception SqlResultSetRowDeleted(string methodname)
{
if (methodname == null)