forked from dotnet/SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlUtil.cs
2107 lines (1869 loc) · 98 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.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Microsoft.Data.Common;
namespace Microsoft.Data.SqlClient
{
internal static class AsyncHelper
{
internal static Task CreateContinuationTask(Task task, Action onSuccess, Action<Exception> onFailure = null)
{
if (task == null)
{
onSuccess();
return null;
}
else
{
TaskCompletionSource<object> completion = new TaskCompletionSource<object>();
ContinueTaskWithState(task, completion,
state: Tuple.Create(onSuccess, onFailure, completion),
onSuccess: (state) =>
{
var parameters = (Tuple<Action, Action<Exception>, TaskCompletionSource<object>>)state;
Action success = parameters.Item1;
TaskCompletionSource<object> taskCompletionSource = parameters.Item3;
success();
taskCompletionSource.SetResult(null);
},
onFailure: (exception, state) =>
{
var parameters = (Tuple<Action, Action<Exception>, TaskCompletionSource<object>>)state;
Action<Exception> failure = parameters.Item2;
failure?.Invoke(exception);
}
);
return completion.Task;
}
}
internal static Task CreateContinuationTaskWithState(Task task, object state, Action<object> onSuccess, Action<Exception, object> onFailure = null)
{
if (task == null)
{
onSuccess(state);
return null;
}
else
{
var completion = new TaskCompletionSource<object>();
ContinueTaskWithState(task, completion, state,
onSuccess: (continueState) =>
{
onSuccess(continueState);
completion.SetResult(null);
},
onFailure: 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), onFailure);
}
internal static void ContinueTask(Task task,
TaskCompletionSource<object> completion,
Action onSuccess,
Action<Exception> onFailure = null,
Action onCancellation = null,
Func<Exception, Exception> exceptionConverter = null
)
{
task.ContinueWith(
tsk =>
{
if (tsk.Exception != null)
{
Exception exc = tsk.Exception.InnerException;
if (exceptionConverter != null)
{
exc = exceptionConverter(exc);
}
try
{
onFailure?.Invoke(exc);
}
finally
{
completion.TrySetException(exc);
}
}
else if (tsk.IsCanceled)
{
try
{
onCancellation?.Invoke();
}
finally
{
completion.TrySetCanceled();
}
}
else
{
try
{
onSuccess();
}
catch (Exception e)
{
completion.SetException(e);
}
}
}, TaskScheduler.Default
);
}
// the same logic as ContinueTask but with an added state parameter to allow the caller to avoid the use of a closure
// the parameter allocation cannot be avoided here and using closure names is clearer than Tuple numbered properties
internal static void ContinueTaskWithState(Task task,
TaskCompletionSource<object> completion,
object state,
Action<object> onSuccess,
Action<Exception, object> onFailure = null,
Action<object> onCancellation = null,
Func<Exception, Exception> exceptionConverter = null
)
{
task.ContinueWith(
tsk =>
{
if (tsk.Exception != null)
{
Exception exc = tsk.Exception.InnerException;
if (exceptionConverter != null)
{
exc = exceptionConverter(exc);
}
try
{
onFailure?.Invoke(exc, state);
}
finally
{
completion.TrySetException(exc);
}
}
else if (tsk.IsCanceled)
{
try
{
onCancellation?.Invoke(state);
}
finally
{
completion.TrySetCanceled();
}
}
else
{
try
{
onSuccess(state);
}
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)
{
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());
}
});
}
}
}
internal static 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
//
internal static Exception CannotGetDTCAddress()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_CannotGetDTCAddress));
}
internal static Exception InvalidInternalPacketSize(string str)
{
return ADP.ArgumentOutOfRange(str);
}
internal static Exception InvalidPacketSize()
{
return ADP.ArgumentOutOfRange(System.SRHelper.GetString(SR.SQL_InvalidTDSPacketSize));
}
internal static Exception InvalidPacketSizeValue()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InvalidPacketSizeValue));
}
internal static Exception InvalidSSPIPacketSize()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InvalidSSPIPacketSize));
}
internal static Exception AuthenticationAndIntegratedSecurity()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_AuthenticationAndIntegratedSecurity));
}
internal static Exception IntegratedWithPassword()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_IntegratedWithPassword));
}
internal static Exception InteractiveWithPassword()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InteractiveWithPassword));
}
internal static Exception DeviceFlowWithUsernamePassword()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_DeviceFlowWithUsernamePassword));
}
static internal Exception SettingIntegratedWithCredential()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingIntegratedWithCredential));
}
static internal Exception SettingInteractiveWithCredential()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingInteractiveWithCredential));
}
static internal Exception SettingDeviceFlowWithCredential()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingDeviceFlowWithCredential));
}
static internal Exception SettingCredentialWithIntegratedArgument()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_SettingCredentialWithIntegrated));
}
static internal Exception SettingCredentialWithInteractiveArgument()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_SettingCredentialWithInteractive));
}
static internal Exception SettingCredentialWithDeviceFlowArgument()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_SettingCredentialWithDeviceFlow));
}
static internal Exception SettingCredentialWithIntegratedInvalid()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingCredentialWithIntegrated));
}
static internal Exception SettingCredentialWithInteractiveInvalid()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingCredentialWithInteractive));
}
static internal Exception SettingCredentialWithDeviceFlowInvalid()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SettingCredentialWithDeviceFlow));
}
internal static Exception NullEmptyTransactionName()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_NullEmptyTransactionName));
}
internal static Exception UserInstanceFailoverNotCompatible()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_UserInstanceFailoverNotCompatible));
}
internal static Exception CredentialsNotProvided(SqlAuthenticationMethod auth)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_CredentialsNotProvided, DbConnectionStringBuilderUtil.AuthenticationTypeToString(auth)));
}
internal static Exception ParsingErrorLibraryType(ParsingErrorState state, int libraryType)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorAuthLibraryType, ((int)state).ToString(CultureInfo.InvariantCulture), libraryType));
}
internal static Exception InvalidSQLServerVersionUnknown()
{
return ADP.DataAdapter(System.SRHelper.GetString(SR.SQL_InvalidSQLServerVersionUnknown));
}
internal static Exception SynchronousCallMayNotPend()
{
return new Exception(System.SRHelper.GetString(SR.Sql_InternalError));
}
internal static Exception ConnectionLockedForBcpEvent()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ConnectionLockedForBcpEvent));
}
internal static Exception InstanceFailure()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_InstanceFailure));
}
internal static Exception ChangePasswordArgumentMissing(string argumentName)
{
return ADP.ArgumentNull(System.SRHelper.GetString(SR.SQL_ChangePasswordArgumentMissing, argumentName));
}
internal static Exception ChangePasswordConflictsWithSSPI()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_ChangePasswordConflictsWithSSPI));
}
internal static Exception ChangePasswordRequiresYukon()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ChangePasswordRequiresYukon));
}
internal static Exception ChangePasswordUseOfUnallowedKey(string key)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ChangePasswordUseOfUnallowedKey, key));
}
internal static Exception GlobalizationInvariantModeNotSupported()
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SQL_GlobalizationInvariantModeNotSupported));
}
//
// Global Transactions.
//
internal static Exception GlobalTransactionsNotEnabled()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.GT_Disabled));
}
internal static Exception UnknownSysTxIsolationLevel(System.Transactions.IsolationLevel isolationLevel)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_UnknownSysTxIsolationLevel, isolationLevel.ToString()));
}
internal static Exception InvalidPartnerConfiguration(string server, string database)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_InvalidPartnerConfiguration, server, database));
}
internal static Exception BatchedUpdateColumnEncryptionSettingMismatch()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.TCE_BatchedUpdateColumnEncryptionSettingMismatch, "SqlCommandColumnEncryptionSetting", "SelectCommand", "InsertCommand", "UpdateCommand", "DeleteCommand"));
}
internal static Exception MARSUnsupportedOnConnection()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_MarsUnsupportedOnConnection));
}
internal static Exception CannotModifyPropertyAsyncOperationInProgress([CallerMemberName] string property = "")
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_CannotModifyPropertyAsyncOperationInProgress, property));
}
internal static Exception NonLocalSSEInstance()
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SQL_NonLocalSSEInstance));
}
// SQL.ActiveDirectoryAuth
//
internal static Exception UnsupportedAuthentication(string authentication)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SQL_UnsupportedAuthentication, authentication));
}
internal static Exception UnsupportedSqlAuthenticationMethod(SqlAuthenticationMethod authentication)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SQL_UnsupportedSqlAuthenticationMethod, authentication));
}
internal static Exception UnsupportedAuthenticationSpecified(SqlAuthenticationMethod authentication)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_UnsupportedAuthenticationSpecified, authentication));
}
internal static Exception CannotCreateAuthProvider(string authentication, string type, Exception e)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_CannotCreateAuthProvider, authentication, type), e);
}
internal static Exception CannotCreateSqlAuthInitializer(string type, Exception e)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_CannotCreateAuthInitializer, type), e);
}
internal static Exception CannotInitializeAuthProvider(string type, Exception e)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_CannotInitializeAuthProvider, type), e);
}
internal static Exception UnsupportedAuthenticationByProvider(string authentication, string type)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SQL_UnsupportedAuthenticationByProvider, type, authentication));
}
internal static Exception CannotFindAuthProvider(string authentication)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_CannotFindAuthProvider, authentication));
}
internal static Exception CannotGetAuthProviderConfig(Exception e)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_CannotGetAuthProviderConfig), e);
}
internal static Exception ParameterCannotBeEmpty(string paramName)
{
return ADP.ArgumentNull(System.SRHelper.GetString(SR.SQL_ParameterCannotBeEmpty, paramName));
}
internal static Exception ActiveDirectoryInteractiveTimeout()
{
return ADP.TimeoutException(SR.SQL_Timeout_Active_Directory_Interactive_Authentication);
}
internal static Exception ActiveDirectoryDeviceFlowTimeout()
{
return ADP.TimeoutException(SR.SQL_Timeout_Active_Directory_DeviceFlow_Authentication);
}
//
// SQL.DataCommand
//
internal static ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, int value)
{
return ADP.ArgumentOutOfRange(System.SRHelper.GetString(SR.SQL_NotSupportedEnumerationValue, type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name);
}
internal static 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);
}
internal static ArgumentOutOfRangeException NotSupportedIsolationLevel(System.Data.IsolationLevel value)
{
#if DEBUG
switch (value)
{
case System.Data.IsolationLevel.Unspecified:
case System.Data.IsolationLevel.ReadCommitted:
case System.Data.IsolationLevel.ReadUncommitted:
case System.Data.IsolationLevel.RepeatableRead:
case System.Data.IsolationLevel.Serializable:
case System.Data.IsolationLevel.Snapshot:
Debug.Fail("valid IsolationLevel " + value.ToString());
break;
case System.Data.IsolationLevel.Chaos:
break;
default:
Debug.Fail("invalid IsolationLevel " + value.ToString());
break;
}
#endif
return NotSupportedEnumerationValue(typeof(System.Data.IsolationLevel), (int)value);
}
internal static Exception OperationCancelled()
{
Exception exception = ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_OperationCancelled));
return exception;
}
internal static Exception PendingBeginXXXExists()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_PendingBeginXXXExists));
}
internal static ArgumentOutOfRangeException InvalidSqlDependencyTimeout(string param)
{
return ADP.ArgumentOutOfRange(System.SRHelper.GetString(SR.SqlDependency_InvalidTimeout), param);
}
internal static Exception NonXmlResult()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_NonXmlResult));
}
//
// SQL.DataParameter
//
internal static Exception InvalidUdt3PartNameFormat()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InvalidUdt3PartNameFormat));
}
internal static Exception InvalidParameterTypeNameFormat()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InvalidParameterTypeNameFormat));
}
internal static Exception InvalidParameterNameLength(string value)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_InvalidParameterNameLength, value));
}
internal static Exception PrecisionValueOutOfRange(byte precision)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_PrecisionValueOutOfRange, precision.ToString(CultureInfo.InvariantCulture)));
}
internal static Exception ScaleValueOutOfRange(byte scale)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_ScaleValueOutOfRange, scale.ToString(CultureInfo.InvariantCulture)));
}
internal static Exception TimeScaleValueOutOfRange(byte scale)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_TimeScaleValueOutOfRange, scale.ToString(CultureInfo.InvariantCulture)));
}
internal static Exception InvalidSqlDbType(SqlDbType value)
{
return ADP.InvalidEnumerationValue(typeof(SqlDbType), (int)value);
}
internal static Exception UnsupportedTVPOutputParameter(ParameterDirection direction, string paramName)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SqlParameter_UnsupportedTVPOutputParameter,
direction.ToString(), paramName));
}
internal static Exception DBNullNotSupportedForTVPValues(string paramName)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SqlParameter_DBNullNotSupportedForTVP, paramName));
}
internal static Exception UnexpectedTypeNameForNonStructParams(string paramName)
{
return ADP.NotSupported(System.SRHelper.GetString(SR.SqlParameter_UnexpectedTypeNameForNonStruct, paramName));
}
internal static Exception ParameterInvalidVariant(string paramName)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParameterInvalidVariant, paramName));
}
internal static Exception MustSetTypeNameForParam(string paramType, string paramName)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_ParameterTypeNameRequired, paramType, paramName));
}
internal static Exception NullSchemaTableDataTypeNotSupported(string columnName)
{
return ADP.Argument(System.SRHelper.GetString(SR.NullSchemaTableDataTypeNotSupported, columnName));
}
internal static Exception InvalidSchemaTableOrdinals()
{
return ADP.Argument(System.SRHelper.GetString(SR.InvalidSchemaTableOrdinals));
}
internal static Exception EnumeratedRecordMetaDataChanged(string fieldName, int recordNumber)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_EnumeratedRecordMetaDataChanged, fieldName, recordNumber));
}
internal static Exception EnumeratedRecordFieldCountChanged(int recordNumber)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_EnumeratedRecordFieldCountChanged, recordNumber));
}
//
// SQL.SqlDataAdapter
//
//
// SQL.TDSParser
//
internal static Exception InvalidTDSVersion()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_InvalidTDSVersion));
}
internal static Exception ParsingError()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingError));
}
internal static Exception ParsingError(ParsingErrorState state)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorWithState, ((int)state).ToString(CultureInfo.InvariantCulture)));
}
internal static Exception ParsingError(ParsingErrorState state, Exception innerException)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorWithState, ((int)state).ToString(CultureInfo.InvariantCulture)), innerException);
}
internal static Exception ParsingErrorValue(ParsingErrorState state, int value)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorValue, ((int)state).ToString(CultureInfo.InvariantCulture), value));
}
internal static Exception ParsingErrorFeatureId(ParsingErrorState state, int featureId)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorFeatureId, ((int)state).ToString(CultureInfo.InvariantCulture), featureId));
}
internal static Exception ParsingErrorToken(ParsingErrorState state, int token)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorToken, ((int)state).ToString(CultureInfo.InvariantCulture), token));
}
internal static Exception ParsingErrorLength(ParsingErrorState state, int length)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorLength, ((int)state).ToString(CultureInfo.InvariantCulture), length));
}
internal static Exception ParsingErrorStatus(ParsingErrorState state, int status)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorStatus, ((int)state).ToString(CultureInfo.InvariantCulture), status));
}
internal static Exception ParsingErrorOffset(ParsingErrorState state, int offset)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ParsingErrorOffset, ((int)state).ToString(CultureInfo.InvariantCulture), offset));
}
internal static Exception MoneyOverflow(string moneyValue)
{
return ADP.Overflow(System.SRHelper.GetString(SR.SQL_MoneyOverflow, moneyValue));
}
internal static Exception SmallDateTimeOverflow(string datetime)
{
return ADP.Overflow(System.SRHelper.GetString(SR.SQL_SmallDateTimeOverflow, datetime));
}
internal static Exception SNIPacketAllocationFailure()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_SNIPacketAllocationFailure));
}
internal static Exception TimeOverflow(string time)
{
return ADP.Overflow(System.SRHelper.GetString(SR.SQL_TimeOverflow, time));
}
//
// SQL.SqlDataReader
//
internal static Exception InvalidRead()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_InvalidRead));
}
internal static Exception NonBlobColumn(string columnName)
{
return ADP.InvalidCast(System.SRHelper.GetString(SR.SQL_NonBlobColumn, columnName));
}
internal static Exception NonCharColumn(string columnName)
{
return ADP.InvalidCast(System.SRHelper.GetString(SR.SQL_NonCharColumn, columnName));
}
internal static Exception StreamNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(System.SRHelper.GetString(SR.SQL_StreamNotSupportOnColumnType, columnName));
}
internal static Exception StreamNotSupportOnEncryptedColumn(string columnName)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.TCE_StreamNotSupportOnEncryptedColumn, columnName, "Stream"));
}
internal static Exception SequentialAccessNotSupportedOnEncryptedColumn(string columnName)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.TCE_SequentialAccessNotSupportedOnEncryptedColumn, columnName, "CommandBehavior=SequentialAccess"));
}
internal static Exception TextReaderNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(System.SRHelper.GetString(SR.SQL_TextReaderNotSupportOnColumnType, columnName));
}
internal static Exception XmlReaderNotSupportOnColumnType(string columnName)
{
return ADP.InvalidCast(System.SRHelper.GetString(SR.SQL_XmlReaderNotSupportOnColumnType, columnName));
}
internal static Exception UDTUnexpectedResult(string exceptionText)
{
return ADP.TypeLoad(System.SRHelper.GetString(SR.SQLUDT_Unexpected, exceptionText));
}
//
// SQL.SqlDependency
//
internal static Exception SqlCommandHasExistingSqlNotificationRequest()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQLNotify_AlreadyHasCommand));
}
internal static Exception SqlDepDefaultOptionsButNoStart()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_DefaultOptionsButNoStart));
}
internal static Exception SqlDependencyDatabaseBrokerDisabled()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_DatabaseBrokerDisabled));
}
internal static Exception SqlDependencyEventNoDuplicate()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_EventNoDuplicate));
}
internal static Exception SqlDependencyDuplicateStart()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_DuplicateStart));
}
internal static Exception SqlDependencyIdMismatch()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_IdMismatch));
}
internal static Exception SqlDependencyNoMatchingServerStart()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_NoMatchingServerStart));
}
internal static Exception SqlDependencyNoMatchingServerDatabaseStart()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlDependency_NoMatchingServerDatabaseStart));
}
//
// SQL.SqlDelegatedTransaction
//
internal static TransactionPromotionException PromotionFailed(Exception inner)
{
TransactionPromotionException e = new TransactionPromotionException(System.SRHelper.GetString(SR.SqlDelegatedTransaction_PromotionFailed), inner);
ADP.TraceExceptionAsReturnValue(e);
return e;
}
//Failure while attempting to promote transaction.
//
// SQL.SqlMetaData
//
internal static Exception UnexpectedUdtTypeNameForNonUdtParams()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQLUDT_UnexpectedUdtTypeName));
}
internal static Exception MustSetUdtTypeNameForUdtParams()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQLUDT_InvalidUdtTypeName));
}
internal static Exception UDTInvalidSqlType(string typeName)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQLUDT_InvalidSqlType, typeName));
}
internal static Exception UDTInvalidSize(int maxSize, int maxSupportedSize)
{
throw ADP.ArgumentOutOfRange(System.SRHelper.GetString(SR.SQLUDT_InvalidSize, maxSize, maxSupportedSize));
}
internal static Exception InvalidSqlDbTypeForConstructor(SqlDbType type)
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlMetaData_InvalidSqlDbTypeForConstructorFormat, type.ToString()));
}
internal static Exception NameTooLong(string parameterName)
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlMetaData_NameTooLong), parameterName);
}
internal static Exception InvalidSortOrder(SortOrder order)
{
return ADP.InvalidEnumerationValue(typeof(SortOrder), (int)order);
}
internal static Exception MustSpecifyBothSortOrderAndOrdinal(SortOrder order, int ordinal)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlMetaData_SpecifyBothSortOrderAndOrdinal, order.ToString(), ordinal));
}
internal static Exception UnsupportedColumnTypeForSqlProvider(string columnName, string typeName)
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlProvider_InvalidDataColumnType, columnName, typeName));
}
internal static Exception InvalidColumnMaxLength(string columnName, long maxLength)
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlProvider_InvalidDataColumnMaxLength, columnName, maxLength));
}
internal static Exception InvalidColumnPrecScale()
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlMisc_InvalidPrecScaleMessage));
}
internal static Exception NotEnoughColumnsInStructuredType()
{
return ADP.Argument(System.SRHelper.GetString(SR.SqlProvider_NotEnoughColumnsInStructuredType));
}
internal static Exception DuplicateSortOrdinal(int sortOrdinal)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlProvider_DuplicateSortOrdinal, sortOrdinal));
}
internal static Exception MissingSortOrdinal(int sortOrdinal)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlProvider_MissingSortOrdinal, sortOrdinal));
}
internal static Exception SortOrdinalGreaterThanFieldCount(int columnOrdinal, int sortOrdinal)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlProvider_SortOrdinalGreaterThanFieldCount, sortOrdinal, columnOrdinal));
}
internal static Exception IEnumerableOfSqlDataRecordHasNoRows()
{
return ADP.Argument(System.SRHelper.GetString(SR.IEnumerableOfSqlDataRecordHasNoRows));
}
//
// SQL.BulkLoad
//
internal static Exception BulkLoadMappingInaccessible()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadMappingInaccessible));
}
internal static Exception BulkLoadMappingsNamesOrOrdinalsOnly()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadMappingsNamesOrOrdinalsOnly));
}
internal static Exception BulkLoadCannotConvertValue(Type sourcetype, MetaType metatype, int ordinal, int rowNumber, bool isEncrypted, string columnName, string value, Exception e)
{
string quotedValue = string.Empty;
if (!isEncrypted)
{
quotedValue = string.Format(" '{0}'", (value.Length > 100 ? value.Substring(0, 100) : value));
}
if (rowNumber == -1)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadCannotConvertValueWithoutRowNo, quotedValue, sourcetype.Name, metatype.TypeName, ordinal, columnName), e);
}
else
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadCannotConvertValue, quotedValue, sourcetype.Name, metatype.TypeName, ordinal, columnName, rowNumber), e);
}
}
internal static Exception BulkLoadNonMatchingColumnMapping()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadNonMatchingColumnMapping));
}
internal static Exception BulkLoadNonMatchingColumnName(string columnName)
{
return BulkLoadNonMatchingColumnName(columnName, null);
}
internal static Exception BulkLoadNonMatchingColumnName(string columnName, Exception e)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadNonMatchingColumnName, columnName), e);
}
internal static Exception BulkLoadNullEmptyColumnName(string paramName)
{
return ADP.Argument(string.Format(System.SRHelper.GetString(SR.SQL_ParameterCannotBeEmpty), paramName));
}
internal static Exception BulkLoadUnspecifiedSortOrder()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_BulkLoadUnspecifiedSortOrder));
}
internal static Exception BulkLoadInvalidOrderHint()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_BulkLoadInvalidOrderHint));
}
internal static Exception BulkLoadOrderHintInvalidColumn(string columnName)
{
return ADP.InvalidOperation(string.Format(System.SRHelper.GetString(SR.SQL_BulkLoadOrderHintInvalidColumn), columnName));
}
internal static Exception BulkLoadOrderHintDuplicateColumn(string columnName)
{
return ADP.InvalidOperation(string.Format(System.SRHelper.GetString(SR.SQL_BulkLoadOrderHintDuplicateColumn), columnName));
}
internal static Exception BulkLoadStringTooLong(string tableName, string columnName, string truncatedValue)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadStringTooLong, tableName, columnName, truncatedValue));
}
internal static Exception BulkLoadInvalidVariantValue()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadInvalidVariantValue));
}
internal static Exception BulkLoadInvalidTimeout(int timeout)
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_BulkLoadInvalidTimeout, timeout.ToString(CultureInfo.InvariantCulture)));
}
internal static Exception BulkLoadExistingTransaction()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadExistingTransaction));
}
internal static Exception BulkLoadNoCollation()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadNoCollation));
}
internal static Exception BulkLoadConflictingTransactionOption()
{
return ADP.Argument(System.SRHelper.GetString(SR.SQL_BulkLoadConflictingTransactionOption));
}
internal static Exception BulkLoadLcidMismatch(int sourceLcid, string sourceColumnName, int destinationLcid, string destinationColumnName)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.Sql_BulkLoadLcidMismatch, sourceLcid, sourceColumnName, destinationLcid, destinationColumnName));
}
internal static Exception InvalidOperationInsideEvent()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadInvalidOperationInsideEvent));
}
internal static Exception BulkLoadMissingDestinationTable()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadMissingDestinationTable));
}
internal static Exception BulkLoadInvalidDestinationTable(string tableName, Exception inner)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadInvalidDestinationTable, tableName), inner);
}
internal static Exception BulkLoadBulkLoadNotAllowDBNull(string columnName)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadNotAllowDBNull, columnName));
}
internal static Exception BulkLoadPendingOperation()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_BulkLoadPendingOperation));
}
internal static Exception InvalidTableDerivedPrecisionForTvp(string columnName, byte precision)
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SqlParameter_InvalidTableDerivedPrecisionForTvp, precision, columnName, System.Data.SqlTypes.SqlDecimal.MaxPrecision));
}
//
// transactions.
//
internal static Exception ConnectionDoomed()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_ConnectionDoomed));
}
internal static Exception OpenResultCountExceeded()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_OpenResultCountExceeded));
}
internal static Exception UnsupportedSysTxForGlobalTransactions()
{
return ADP.InvalidOperation(System.SRHelper.GetString(SR.SQL_UnsupportedSysTxVersion));
}
internal static readonly byte[] AttentionHeader = new byte[] {
TdsEnums.MT_ATTN, // Message Type
TdsEnums.ST_EOM, // Status
TdsEnums.HEADER_LEN >> 8, // length - upper byte
TdsEnums.HEADER_LEN & 0xff, // length - lower byte
0, // spid
0, // spid
0, // packet (out of band)
0 // window
};
//
// MultiSubnetFailover
//