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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597
|
//------------------------------------------------------------------------------
// <copyright file="AdapterUtil.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Data.Common {
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.ProviderBase;
#if !MOBILE
using System.Data.Odbc;
using System.Data.OleDb;
#endif
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Data.SqlClient;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using SysTx = System.Transactions;
#if !MOBILE
using SysES = System.EnterpriseServices;
#endif
using System.Runtime.Versioning;
using Microsoft.SqlServer.Server;
internal static class ADP {
// The class ADP defines the exceptions that are specific to the Adapters.f
// 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.
public const CompareOptions DefaultCompareOptions = CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
static internal Task<T> CreatedTaskWithException<T>(Exception ex) {
TaskCompletionSource<T> completion = new TaskCompletionSource<T>();
completion.SetException(ex);
return completion.Task;
}
static internal Task<T> CreatedTaskWithCancellation<T>() {
TaskCompletionSource<T> completion = new TaskCompletionSource<T>();
completion.SetCanceled();
return completion.Task;
}
static internal Exception ExceptionWithStackTrace(Exception e)
{
try {
throw e;
}
catch (Exception caught) {
return caught;
}
}
static internal Task<bool> s_trueTask = Task.FromResult<bool>(true);
static internal Task<bool> s_falseTask = Task.FromResult<bool>(false);
#if MONO
static internal Task<bool> TrueTask => s_trueTask;
static internal Task<bool> FalseTask => s_falseTask;
#endif
[BidMethod] // this method accepts BID format as an argument, this attribute allows FXCopBid rule to validate calls to it
static private void TraceException(
string trace,
[BidArgumentType(typeof(String))] Exception e) {
Debug.Assert(null != e, "TraceException: null Exception");
if (null != e) {
Bid.Trace(trace, e.ToString()); // will include callstack if permission is available
}
}
static internal void TraceExceptionAsReturnValue(Exception e) {
TraceException("<comm.ADP.TraceException|ERR|THROW> '%ls'\n", e);
}
static internal void TraceExceptionForCapture(Exception e) {
Debug.Assert(ADP.IsCatchableExceptionType(e), "Invalid exception type, should have been re-thrown!");
TraceException("<comm.ADP.TraceException|ERR|CATCH> '%ls'\n", e);
}
static internal void TraceExceptionWithoutRethrow(Exception e) {
Debug.Assert(ADP.IsCatchableExceptionType(e), "Invalid exception type, should have been re-thrown!");
TraceException("<comm.ADP.TraceException|ERR|CATCH> '%ls'\n", e);
}
//
// COM+ exceptions
//
static internal ArgumentException Argument(string error) {
ArgumentException e = new ArgumentException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException Argument(string error, Exception inner) {
ArgumentException e = new ArgumentException(error, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException Argument(string error, string parameter) {
ArgumentException e = new ArgumentException(error, parameter);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException Argument(string error, string parameter, Exception inner) {
ArgumentException e = new ArgumentException(error, parameter, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentNullException ArgumentNull(string parameter) {
ArgumentNullException e = new ArgumentNullException(parameter);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentNullException ArgumentNull(string parameter, string error) {
ArgumentNullException e = new ArgumentNullException(parameter, error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentOutOfRangeException ArgumentOutOfRange(string parameterName) {
ArgumentOutOfRangeException e = new ArgumentOutOfRangeException(parameterName);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentOutOfRangeException ArgumentOutOfRange(string message, string parameterName) {
ArgumentOutOfRangeException e = new ArgumentOutOfRangeException(parameterName, message);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentOutOfRangeException ArgumentOutOfRange(string message, string parameterName, object value) {
ArgumentOutOfRangeException e = new ArgumentOutOfRangeException(parameterName, value, message);
TraceExceptionAsReturnValue(e);
return e;
}
#if !MOBILE
static internal ConfigurationException Configuration(string message) {
ConfigurationException e = new ConfigurationErrorsException(message);
TraceExceptionAsReturnValue(e);
return e;
}
static internal ConfigurationException Configuration(string message, XmlNode node) {
ConfigurationException e = new ConfigurationErrorsException(message, node);
TraceExceptionAsReturnValue(e);
return e;
}
#endif
static internal DataException Data(string message) {
DataException e = new DataException(message);
TraceExceptionAsReturnValue(e);
return e;
}
static internal IndexOutOfRangeException IndexOutOfRange(int value) {
IndexOutOfRangeException e = new IndexOutOfRangeException(value.ToString(CultureInfo.InvariantCulture));
TraceExceptionAsReturnValue(e);
return e;
}
static internal IndexOutOfRangeException IndexOutOfRange(string error) {
IndexOutOfRangeException e = new IndexOutOfRangeException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal IndexOutOfRangeException IndexOutOfRange() {
IndexOutOfRangeException e = new IndexOutOfRangeException();
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidCastException InvalidCast(string error) {
return InvalidCast(error, null);
}
static internal InvalidCastException InvalidCast(string error, Exception inner) {
InvalidCastException e = new InvalidCastException(error, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidOperationException InvalidOperation(string error) {
InvalidOperationException e = new InvalidOperationException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal TimeoutException TimeoutException(string error) {
TimeoutException e = new TimeoutException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidOperationException InvalidOperation(string error, Exception inner)
{
InvalidOperationException e = new InvalidOperationException(error, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal NotImplementedException NotImplemented(string error) {
NotImplementedException e = new NotImplementedException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal NotSupportedException NotSupported() {
NotSupportedException e = new NotSupportedException();
TraceExceptionAsReturnValue(e);
return e;
}
static internal NotSupportedException NotSupported(string error) {
NotSupportedException e = new NotSupportedException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal OverflowException Overflow(string error) {
return Overflow(error, null);
}
static internal OverflowException Overflow(string error, Exception inner) {
OverflowException e = new OverflowException(error, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal PlatformNotSupportedException PropertyNotSupported(string property) {
PlatformNotSupportedException e = new PlatformNotSupportedException(Res.GetString(Res.ADP_PropertyNotSupported, property));
TraceExceptionAsReturnValue(e);
return e;
}
static internal TypeLoadException TypeLoad(string error) {
TypeLoadException e = new TypeLoadException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidCastException InvalidCast() {
InvalidCastException e = new InvalidCastException();
TraceExceptionAsReturnValue(e);
return e;
}
static internal IOException IO(string error) {
IOException e = new IOException(error);
TraceExceptionAsReturnValue(e);
return e;
}
static internal IOException IO(string error, Exception inner) {
IOException e = new IOException(error, inner);
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidOperationException DataAdapter(string error) {
return InvalidOperation(error);
}
static internal InvalidOperationException DataAdapter(string error, Exception inner) {
return InvalidOperation(error, inner);
}
static private InvalidOperationException Provider(string error) {
return InvalidOperation(error);
}
static internal ObjectDisposedException ObjectDisposed(object instance) {
ObjectDisposedException e = new ObjectDisposedException(instance.GetType().Name);
TraceExceptionAsReturnValue(e);
return e;
}
static internal InvalidOperationException MethodCalledTwice(string method) {
InvalidOperationException e = new InvalidOperationException(Res.GetString(Res.ADP_CalledTwice, method));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException IncorrectAsyncResult() {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_IncorrectAsyncResult), "AsyncResult");
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException SingleValuedProperty(string propertyName, string value) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_SingleValuedProperty, propertyName, value));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException DoubleValuedProperty(string propertyName, string value1, string value2) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_DoubleValuedProperty, propertyName, value1, value2));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException InvalidPrefixSuffix() {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_InvalidPrefixSuffix));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException InvalidMultipartName(string property, string value) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_InvalidMultipartName, Res.GetString(property), value));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException InvalidMultipartNameIncorrectUsageOfQuotes(string property, string value) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_InvalidMultipartNameQuoteUsage, Res.GetString(property), value));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException InvalidMultipartNameToManyParts(string property, string value, int limit) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_InvalidMultipartNameToManyParts, Res.GetString(property), value, limit));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException BadParameterName(string parameterName) {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_BadParameterName, parameterName));
TraceExceptionAsReturnValue(e);
return e;
}
static internal ArgumentException MultipleReturnValue() {
ArgumentException e = new ArgumentException(Res.GetString(Res.ADP_MultipleReturnValue));
TraceExceptionAsReturnValue(e);
return e;
}
//
// Helper Functions
//
static internal void CheckArgumentLength(string value, string parameterName) {
CheckArgumentNull(value, parameterName);
if (0 == value.Length) {
throw Argument(Res.GetString(Res.ADP_EmptyString, parameterName)); // MDAC 94859
}
}
static internal void CheckArgumentLength(Array value, string parameterName) {
CheckArgumentNull(value, parameterName);
if (0 == value.Length) {
throw Argument(Res.GetString(Res.ADP_EmptyArray, parameterName));
}
}
static internal void CheckArgumentNull(object value, string parameterName) {
if (null == value) {
throw ArgumentNull(parameterName);
}
}
// only StackOverflowException & ThreadAbortException are sealed classes
static private readonly Type StackOverflowType = typeof(StackOverflowException);
static private readonly Type OutOfMemoryType = typeof(OutOfMemoryException);
static private readonly Type ThreadAbortType = typeof(ThreadAbortException);
static private readonly Type NullReferenceType = typeof(NullReferenceException);
static private readonly Type AccessViolationType = typeof(AccessViolationException);
static private readonly Type SecurityType = typeof(SecurityException);
static internal bool IsCatchableExceptionType (Exception e) {
// a 'catchable' exception is defined by what it is not.
Debug.Assert(e != null, "Unexpected null exception!");
Type type = e.GetType();
return ( (type != StackOverflowType) &&
(type != OutOfMemoryType) &&
(type != ThreadAbortType) &&
(type != NullReferenceType) &&
(type != AccessViolationType) &&
!SecurityType.IsAssignableFrom(type));
}
static internal bool IsCatchableOrSecurityExceptionType(Exception e) {
// a 'catchable' exception is defined by what it is not.
// since IsCatchableExceptionType defined SecurityException as not 'catchable'
// this method will return true for SecurityException has being catchable.
// the other way to write this method is, but then SecurityException is checked twice
// return ((e is SecurityException) || IsCatchableExceptionType(e));
Debug.Assert(e != null, "Unexpected null exception!");
Type type = e.GetType();
return ( (type != StackOverflowType) &&
(type != OutOfMemoryType) &&
(type != ThreadAbortType) &&
(type != NullReferenceType) &&
(type != AccessViolationType));
}
// Invalid Enumeration
static internal ArgumentOutOfRangeException InvalidEnumerationValue(Type type, int value) {
return ADP.ArgumentOutOfRange(Res.GetString(Res.ADP_InvalidEnumerationValue, type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name);
}
static internal ArgumentOutOfRangeException NotSupportedEnumerationValue(Type type, string value, string method) {
return ADP.ArgumentOutOfRange(Res.GetString(Res.ADP_NotSupportedEnumerationValue, type.Name, value, method), type.Name);
}
static internal ArgumentOutOfRangeException InvalidAcceptRejectRule(AcceptRejectRule value) {
#if DEBUG
switch(value) {
case AcceptRejectRule.None:
case AcceptRejectRule.Cascade:
Debug.Assert(false, "valid AcceptRejectRule " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(AcceptRejectRule), (int) value);
}
// DbCommandBuilder.CatalogLocation
static internal ArgumentOutOfRangeException InvalidCatalogLocation(CatalogLocation value) {
#if DEBUG
switch(value) {
case CatalogLocation.Start:
case CatalogLocation.End:
Debug.Assert(false, "valid CatalogLocation " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(CatalogLocation), (int) value);
}
static internal ArgumentOutOfRangeException InvalidCommandBehavior(CommandBehavior value) {
#if DEBUG
if ((0 <= (int)value) && ((int)value <= 0x3F)) {
Debug.Assert(false, "valid CommandType " + value.ToString());
}
#endif
return InvalidEnumerationValue(typeof(CommandBehavior), (int) value);
}
static internal void ValidateCommandBehavior(CommandBehavior value) {
if (((int)value < 0) || (0x3F < (int)value)) {
throw InvalidCommandBehavior(value);
}
}
static internal ArgumentException InvalidArgumentLength(string argumentName, int limit) {
return Argument(Res.GetString(Res.ADP_InvalidArgumentLength, argumentName, limit));
}
static internal ArgumentException MustBeReadOnly(string argumentName) {
return Argument(Res.GetString(Res.ADP_MustBeReadOnly, argumentName));
}
// IDbCommand.CommandType
static internal ArgumentOutOfRangeException InvalidCommandType(CommandType value) {
#if DEBUG
switch(value) {
case CommandType.Text:
case CommandType.StoredProcedure:
case CommandType.TableDirect:
Debug.Assert(false, "valid CommandType " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(CommandType), (int) value);
}
static internal ArgumentOutOfRangeException InvalidConflictOptions(ConflictOption value) {
#if DEBUG
switch(value) {
case ConflictOption.CompareAllSearchableValues:
case ConflictOption.CompareRowVersion:
case ConflictOption.OverwriteChanges:
Debug.Assert(false, "valid ConflictOption " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(ConflictOption), (int) value);
}
// IDataAdapter.Update
static internal ArgumentOutOfRangeException InvalidDataRowState(DataRowState value) {
#if DEBUG
switch(value) {
case DataRowState.Detached:
case DataRowState.Unchanged:
case DataRowState.Added:
case DataRowState.Deleted:
case DataRowState.Modified:
Debug.Assert(false, "valid DataRowState " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(DataRowState), (int) value);
}
// IDataParameter.SourceVersion
static internal ArgumentOutOfRangeException InvalidDataRowVersion(DataRowVersion value) {
#if DEBUG
switch(value) {
case DataRowVersion.Default:
case DataRowVersion.Current:
case DataRowVersion.Original:
case DataRowVersion.Proposed:
Debug.Assert(false, "valid DataRowVersion " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(DataRowVersion), (int) value);
}
// IDbConnection.BeginTransaction, OleDbTransaction.Begin
static internal ArgumentOutOfRangeException InvalidIsolationLevel(IsolationLevel value) {
#if DEBUG
switch(value) {
case IsolationLevel.Unspecified:
case IsolationLevel.Chaos:
case IsolationLevel.ReadUncommitted:
case IsolationLevel.ReadCommitted:
case IsolationLevel.RepeatableRead:
case IsolationLevel.Serializable:
case IsolationLevel.Snapshot:
Debug.Assert(false, "valid IsolationLevel " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(IsolationLevel), (int) value);
}
// DBDataPermissionAttribute.KeyRestrictionBehavior
static internal ArgumentOutOfRangeException InvalidKeyRestrictionBehavior(KeyRestrictionBehavior value) {
#if DEBUG
switch(value) {
case KeyRestrictionBehavior.PreventUsage:
case KeyRestrictionBehavior.AllowOnly:
Debug.Assert(false, "valid KeyRestrictionBehavior " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(KeyRestrictionBehavior), (int) value);
}
// IDataAdapter.FillLoadOption
static internal ArgumentOutOfRangeException InvalidLoadOption(LoadOption value) {
#if DEBUG
switch(value) {
case LoadOption.OverwriteChanges:
case LoadOption.PreserveChanges:
case LoadOption.Upsert:
Debug.Assert(false, "valid LoadOption " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(LoadOption), (int) value);
}
// IDataAdapter.MissingMappingAction
static internal ArgumentOutOfRangeException InvalidMissingMappingAction(MissingMappingAction value) {
#if DEBUG
switch(value) {
case MissingMappingAction.Passthrough:
case MissingMappingAction.Ignore:
case MissingMappingAction.Error:
Debug.Assert(false, "valid MissingMappingAction " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(MissingMappingAction), (int) value);
}
// IDataAdapter.MissingSchemaAction
static internal ArgumentOutOfRangeException InvalidMissingSchemaAction(MissingSchemaAction value) {
#if DEBUG
switch(value) {
case MissingSchemaAction.Add:
case MissingSchemaAction.Ignore:
case MissingSchemaAction.Error:
case MissingSchemaAction.AddWithKey:
Debug.Assert(false, "valid MissingSchemaAction " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(MissingSchemaAction), (int) value);
}
// IDataParameter.Direction
static internal ArgumentOutOfRangeException InvalidParameterDirection(ParameterDirection value) {
#if DEBUG
switch(value) {
case ParameterDirection.Input:
case ParameterDirection.Output:
case ParameterDirection.InputOutput:
case ParameterDirection.ReturnValue:
Debug.Assert(false, "valid ParameterDirection " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(ParameterDirection), (int) value);
}
static internal ArgumentOutOfRangeException InvalidPermissionState(PermissionState value) {
#if DEBUG
switch(value) {
case PermissionState.Unrestricted:
case PermissionState.None:
Debug.Assert(false, "valid PermissionState " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(PermissionState), (int) value);
}
static internal ArgumentOutOfRangeException InvalidRule(Rule value) {
#if DEBUG
switch(value) {
case Rule.None:
case Rule.Cascade:
case Rule.SetNull:
case Rule.SetDefault:
Debug.Assert(false, "valid Rule " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(Rule), (int) value);
}
// IDataAdapter.FillSchema
static internal ArgumentOutOfRangeException InvalidSchemaType(SchemaType value) {
#if DEBUG
switch(value) {
case SchemaType.Source:
case SchemaType.Mapped:
Debug.Assert(false, "valid SchemaType " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(SchemaType), (int) value);
}
// RowUpdatingEventArgs.StatementType
static internal ArgumentOutOfRangeException InvalidStatementType(StatementType value) {
#if DEBUG
switch(value) {
case StatementType.Select:
case StatementType.Insert:
case StatementType.Update:
case StatementType.Delete:
case StatementType.Batch:
Debug.Assert(false, "valid StatementType " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(StatementType), (int) value);
}
// IDbCommand.UpdateRowSource
static internal ArgumentOutOfRangeException InvalidUpdateRowSource(UpdateRowSource value) {
#if DEBUG
switch(value) {
case UpdateRowSource.None:
case UpdateRowSource.OutputParameters:
case UpdateRowSource.FirstReturnedRecord:
case UpdateRowSource.Both:
Debug.Assert(false, "valid UpdateRowSource " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(UpdateRowSource), (int) value);
}
// RowUpdatingEventArgs.UpdateStatus
static internal ArgumentOutOfRangeException InvalidUpdateStatus(UpdateStatus value) {
#if DEBUG
switch(value) {
case UpdateStatus.Continue:
case UpdateStatus.ErrorsOccurred:
case UpdateStatus.SkipAllRemainingRows:
case UpdateStatus.SkipCurrentRow:
Debug.Assert(false, "valid UpdateStatus " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(UpdateStatus), (int) value);
}
static internal ArgumentOutOfRangeException NotSupportedCommandBehavior(CommandBehavior value, string method) {
return NotSupportedEnumerationValue(typeof(CommandBehavior), value.ToString(), method);
}
static internal ArgumentOutOfRangeException NotSupportedStatementType(StatementType value, string method) {
return NotSupportedEnumerationValue(typeof(StatementType), value.ToString(), method);
}
static internal ArgumentOutOfRangeException InvalidUserDefinedTypeSerializationFormat(Microsoft.SqlServer.Server.Format value) {
#if DEBUG
switch(value) {
case Microsoft.SqlServer.Server.Format.Unknown:
case Microsoft.SqlServer.Server.Format.Native:
case Microsoft.SqlServer.Server.Format.UserDefined:
Debug.Assert(false, "valid UserDefinedTypeSerializationFormat " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(Microsoft.SqlServer.Server.Format), (int) value);
}
static internal ArgumentOutOfRangeException NotSupportedUserDefinedTypeSerializationFormat(Microsoft.SqlServer.Server.Format value, string method) {
return ADP.NotSupportedEnumerationValue(typeof(Microsoft.SqlServer.Server.Format), value.ToString(), method);
}
//
// DbProviderFactories
//
static internal ArgumentException ConfigProviderNotFound() {
return Argument(Res.GetString(Res.ConfigProviderNotFound));
}
static internal InvalidOperationException ConfigProviderInvalid() {
return InvalidOperation(Res.GetString(Res.ConfigProviderInvalid));
}
#if !MOBILE
static internal ConfigurationException ConfigProviderNotInstalled() {
return Configuration(Res.GetString(Res.ConfigProviderNotInstalled));
}
static internal ConfigurationException ConfigProviderMissing() {
return Configuration(Res.GetString(Res.ConfigProviderMissing));
}
//
// DbProviderConfigurationHandler
//
static internal ConfigurationException ConfigBaseNoChildNodes(XmlNode node) { // Res.Config_base_no_child_nodes
return Configuration(Res.GetString(Res.ConfigBaseNoChildNodes), node);
}
static internal ConfigurationException ConfigBaseElementsOnly(XmlNode node) { // Res.Config_base_elements_only
return Configuration(Res.GetString(Res.ConfigBaseElementsOnly), node);
}
static internal ConfigurationException ConfigUnrecognizedAttributes(XmlNode node) { // Res.Config_base_unrecognized_attribute
return Configuration(Res.GetString(Res.ConfigUnrecognizedAttributes, node.Attributes[0].Name), node);
}
static internal ConfigurationException ConfigUnrecognizedElement(XmlNode node) { // Res.Config_base_unrecognized_element
return Configuration(Res.GetString(Res.ConfigUnrecognizedElement), node);
}
static internal ConfigurationException ConfigSectionsUnique(string sectionName) { // Res.Res.ConfigSectionsUnique
return Configuration(Res.GetString(Res.ConfigSectionsUnique, sectionName));
}
static internal ConfigurationException ConfigRequiredAttributeMissing(string name, XmlNode node) { // Res.Config_base_required_attribute_missing
return Configuration(Res.GetString(Res.ConfigRequiredAttributeMissing, name), node);
}
static internal ConfigurationException ConfigRequiredAttributeEmpty(string name, XmlNode node) { // Res.Config_base_required_attribute_empty
return Configuration(Res.GetString(Res.ConfigRequiredAttributeEmpty, name), node);
}
#endif
//
// DbConnectionOptions, DataAccess
//
static internal ArgumentException ConnectionStringSyntax(int index) {
return Argument(Res.GetString(Res.ADP_ConnectionStringSyntax, index));
}
static internal ArgumentException KeywordNotSupported(string keyword) {
return Argument(Res.GetString(Res.ADP_KeywordNotSupported, keyword));
}
/*
static internal ArgumentException EmptyKeyValue(string keyword) { // MDAC 80715
return Argument(Res.GetString(Res.ADP_EmptyKeyValue, keyword));
}
*/
static internal ArgumentException UdlFileError(Exception inner) {
return Argument(Res.GetString(Res.ADP_UdlFileError), inner);
}
static internal ArgumentException InvalidUDL() {
return Argument(Res.GetString(Res.ADP_InvalidUDL));
}
static internal InvalidOperationException InvalidDataDirectory() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidDataDirectory));
}
static internal ArgumentException InvalidKeyname(string parameterName) {
return Argument(Res.GetString(Res.ADP_InvalidKey), parameterName);
}
static internal ArgumentException InvalidValue(string parameterName) {
return Argument(Res.GetString(Res.ADP_InvalidValue), parameterName);
}
static internal ArgumentException InvalidMinMaxPoolSizeValues() {
return ADP.Argument(Res.GetString(Res.ADP_InvalidMinMaxPoolSizeValues));
}
static internal ArgumentException ConvertFailed(Type fromType, Type toType, Exception innerException) {
return ADP.Argument(Res.GetString(Res.SqlConvert_ConvertFailed, fromType.FullName, toType.FullName), innerException);
}
static internal InvalidOperationException InvalidMixedUsageOfSecureAndClearCredential() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureAndClearCredential));
}
static internal ArgumentException InvalidMixedArgumentOfSecureAndClearCredential() {
return ADP.Argument(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureAndClearCredential));
}
static internal InvalidOperationException InvalidMixedUsageOfSecureCredentialAndIntegratedSecurity() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureCredentialAndIntegratedSecurity));
}
static internal ArgumentException InvalidMixedArgumentOfSecureCredentialAndIntegratedSecurity() {
return ADP.Argument(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureCredentialAndIntegratedSecurity));
}
static internal InvalidOperationException InvalidMixedUsageOfSecureCredentialAndContextConnection()
{
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureCredentialAndContextConnection));
}
static internal ArgumentException InvalidMixedArgumentOfSecureCredentialAndContextConnection()
{
return ADP.Argument(Res.GetString(Res.ADP_InvalidMixedUsageOfSecureCredentialAndContextConnection));
}
static internal InvalidOperationException InvalidMixedUsageOfAccessTokenAndContextConnection() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfAccessTokenAndContextConnection));
}
static internal InvalidOperationException InvalidMixedUsageOfAccessTokenAndIntegratedSecurity() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfAccessTokenAndIntegratedSecurity));
}
static internal InvalidOperationException InvalidMixedUsageOfAccessTokenAndUserIDPassword() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfAccessTokenAndUserIDPassword));
}
static internal Exception InvalidMixedUsageOfAccessTokenAndCredential() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfAccessTokenAndCredential));
}
static internal Exception InvalidMixedUsageOfAccessTokenAndAuthentication() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfAccessTokenAndAuthentication));
}
static internal Exception InvalidMixedUsageOfCredentialAndAccessToken() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_InvalidMixedUsageOfCredentialAndAccessToken));
}
//
// DbConnection
//
static internal InvalidOperationException NoConnectionString() {
return InvalidOperation(Res.GetString(Res.ADP_NoConnectionString));
}
static internal NotImplementedException MethodNotImplemented(string methodName) {
NotImplementedException e = new NotImplementedException(methodName);
TraceExceptionAsReturnValue(e);
return e;
}
static private string ConnectionStateMsg(ConnectionState state) { // MDAC 82165, if the ConnectionState enum to msg the localization looks weird
switch(state) {
case (ConnectionState.Closed):
case (ConnectionState.Connecting|ConnectionState.Broken): // treated the same as closed
return Res.GetString(Res.ADP_ConnectionStateMsg_Closed);
case (ConnectionState.Connecting):
return Res.GetString(Res.ADP_ConnectionStateMsg_Connecting);
case (ConnectionState.Open):
return Res.GetString(Res.ADP_ConnectionStateMsg_Open);
case (ConnectionState.Open|ConnectionState.Executing):
return Res.GetString(Res.ADP_ConnectionStateMsg_OpenExecuting);
case (ConnectionState.Open|ConnectionState.Fetching):
return Res.GetString(Res.ADP_ConnectionStateMsg_OpenFetching);
default:
return Res.GetString(Res.ADP_ConnectionStateMsg, state.ToString());
}
}
#if !MOBILE
static internal ConfigurationException ConfigUnableToLoadXmlMetaDataFile(string settingName){
return Configuration(Res.GetString(Res.OleDb_ConfigUnableToLoadXmlMetaDataFile, settingName));
}
static internal ConfigurationException ConfigWrongNumberOfValues(string settingName){
return Configuration(Res.GetString(Res.OleDb_ConfigWrongNumberOfValues, settingName));
}
#endif
//
// : DbConnectionOptions, DataAccess, SqlClient
//
static internal Exception InvalidConnectionOptionValue(string key) {
return InvalidConnectionOptionValue(key, null);
}
static internal Exception InvalidConnectionOptionValueLength(string key, int limit) {
return Argument(Res.GetString(Res.ADP_InvalidConnectionOptionValueLength, key, limit));
}
static internal Exception InvalidConnectionOptionValue(string key, Exception inner) {
return Argument(Res.GetString(Res.ADP_InvalidConnectionOptionValue, key), inner);
}
static internal Exception MissingConnectionOptionValue(string key, string requiredAdditionalKey) {
return Argument(Res.GetString(Res.ADP_MissingConnectionOptionValue, key, requiredAdditionalKey));
}
//
// DBDataPermission, DataAccess, Odbc
//
static internal Exception InvalidXMLBadVersion() {
return Argument(Res.GetString(Res.ADP_InvalidXMLBadVersion));
}
static internal Exception NotAPermissionElement() {
return Argument(Res.GetString(Res.ADP_NotAPermissionElement));
}
static internal Exception PermissionTypeMismatch() {
return Argument(Res.GetString(Res.ADP_PermissionTypeMismatch));
}
static internal Exception WrongType(Type got, Type expected) {
return Argument(Res.GetString(Res.SQL_WrongType, got.ToString(), expected.ToString()));
}
static internal Exception OdbcNoTypesFromProvider() {
return InvalidOperation(Res.GetString(Res.ADP_OdbcNoTypesFromProvider));
}
//
// DbConnectionPool and related
//
static internal Exception PooledOpenTimeout() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_PooledOpenTimeout));
}
static internal Exception NonPooledOpenTimeout() {
return ADP.TimeoutException(Res.GetString(Res.ADP_NonPooledOpenTimeout));
}
//
// Generic Data Provider Collection
//
static internal ArgumentException CollectionRemoveInvalidObject(Type itemType, ICollection collection) {
return Argument(Res.GetString(Res.ADP_CollectionRemoveInvalidObject, itemType.Name, collection.GetType().Name)); // MDAC 68201
}
static internal ArgumentNullException CollectionNullValue(string parameter, Type collection, Type itemType) {
return ArgumentNull(parameter, Res.GetString(Res.ADP_CollectionNullValue, collection.Name, itemType.Name));
}
static internal IndexOutOfRangeException CollectionIndexInt32(int index, Type collection, int count) {
return IndexOutOfRange(Res.GetString(Res.ADP_CollectionIndexInt32, index.ToString(CultureInfo.InvariantCulture), collection.Name, count.ToString(CultureInfo.InvariantCulture)));
}
static internal IndexOutOfRangeException CollectionIndexString(Type itemType, string propertyName, string propertyValue, Type collection) {
return IndexOutOfRange(Res.GetString(Res.ADP_CollectionIndexString, itemType.Name, propertyName, propertyValue, collection.Name));
}
static internal InvalidCastException CollectionInvalidType(Type collection, Type itemType, object invalidValue) {
return InvalidCast(Res.GetString(Res.ADP_CollectionInvalidType, collection.Name, itemType.Name, invalidValue.GetType().Name));
}
static internal Exception CollectionUniqueValue(Type itemType, string propertyName, string propertyValue) {
return Argument(Res.GetString(Res.ADP_CollectionUniqueValue, itemType.Name, propertyName, propertyValue));
}
static internal ArgumentException ParametersIsNotParent(Type parameterType, ICollection collection) {
return Argument(Res.GetString(Res.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
}
static internal ArgumentException ParametersIsParent(Type parameterType, ICollection collection) {
return Argument(Res.GetString(Res.ADP_CollectionIsNotParent, parameterType.Name, collection.GetType().Name));
}
//
// DbProviderException
//
static internal InvalidOperationException TransactionConnectionMismatch() {
return Provider(Res.GetString(Res.ADP_TransactionConnectionMismatch));
}
static internal InvalidOperationException TransactionCompletedButNotDisposed()
{
return Provider(Res.GetString(Res.ADP_TransactionCompletedButNotDisposed));
}
static internal InvalidOperationException TransactionRequired(string method) {
return Provider(Res.GetString(Res.ADP_TransactionRequired, method));
}
// IDbDataAdapter.Fill(Schema)
static internal InvalidOperationException MissingSelectCommand(string method) {
return Provider(Res.GetString(Res.ADP_MissingSelectCommand, method));
}
//
// AdapterMappingException
//
static private InvalidOperationException DataMapping(string error) {
return InvalidOperation(error);
}
// DataColumnMapping.GetDataColumnBySchemaAction
static internal InvalidOperationException ColumnSchemaExpression(string srcColumn, string cacheColumn) {
return DataMapping(Res.GetString(Res.ADP_ColumnSchemaExpression, srcColumn, cacheColumn));
}
// DataColumnMapping.GetDataColumnBySchemaAction
static internal InvalidOperationException ColumnSchemaMismatch(string srcColumn, Type srcType, DataColumn column) {
return DataMapping(Res.GetString(Res.ADP_ColumnSchemaMismatch, srcColumn, srcType.Name, column.ColumnName, column.DataType.Name));
}
// DataColumnMapping.GetDataColumnBySchemaAction
static internal InvalidOperationException ColumnSchemaMissing(string cacheColumn, string tableName, string srcColumn) {
if (ADP.IsEmpty(tableName)) {
return InvalidOperation(Res.GetString(Res.ADP_ColumnSchemaMissing1, cacheColumn, tableName, srcColumn));
}
return DataMapping(Res.GetString(Res.ADP_ColumnSchemaMissing2, cacheColumn, tableName, srcColumn));
}
// DataColumnMappingCollection.GetColumnMappingBySchemaAction
static internal InvalidOperationException MissingColumnMapping(string srcColumn) {
return DataMapping(Res.GetString(Res.ADP_MissingColumnMapping, srcColumn));
}
// DataTableMapping.GetDataTableBySchemaAction
static internal InvalidOperationException MissingTableSchema(string cacheTable, string srcTable) {
return DataMapping(Res.GetString(Res.ADP_MissingTableSchema, cacheTable, srcTable));
}
// DataTableMappingCollection.GetTableMappingBySchemaAction
static internal InvalidOperationException MissingTableMapping(string srcTable) {
return DataMapping(Res.GetString(Res.ADP_MissingTableMapping, srcTable));
}
// DbDataAdapter.Update
static internal InvalidOperationException MissingTableMappingDestination(string dstTable) {
return DataMapping(Res.GetString(Res.ADP_MissingTableMappingDestination, dstTable));
}
//
// DataColumnMappingCollection, DataAccess
//
static internal Exception InvalidSourceColumn(string parameter) {
return Argument(Res.GetString(Res.ADP_InvalidSourceColumn), parameter);
}
static internal Exception ColumnsAddNullAttempt(string parameter) {
return CollectionNullValue(parameter, typeof(DataColumnMappingCollection), typeof(DataColumnMapping));
}
static internal Exception ColumnsDataSetColumn(string cacheColumn) {
return CollectionIndexString(typeof(DataColumnMapping), ADP.DataSetColumn, cacheColumn, typeof(DataColumnMappingCollection));
}
static internal Exception ColumnsIndexInt32(int index, IColumnMappingCollection collection) {
return CollectionIndexInt32(index, collection.GetType(), collection.Count);
}
static internal Exception ColumnsIndexSource(string srcColumn) {
return CollectionIndexString(typeof(DataColumnMapping), ADP.SourceColumn, srcColumn, typeof(DataColumnMappingCollection));
}
static internal Exception ColumnsIsNotParent(ICollection collection) {
return ParametersIsNotParent(typeof(DataColumnMapping), collection);
}
static internal Exception ColumnsIsParent(ICollection collection) {
return ParametersIsParent(typeof(DataColumnMapping), collection);
}
static internal Exception ColumnsUniqueSourceColumn(string srcColumn) {
return CollectionUniqueValue(typeof(DataColumnMapping), ADP.SourceColumn, srcColumn);
}
static internal Exception NotADataColumnMapping(object value) {
return CollectionInvalidType(typeof(DataColumnMappingCollection), typeof(DataColumnMapping), value);
}
//
// DataTableMappingCollection, DataAccess
//
static internal Exception InvalidSourceTable(string parameter) {
return Argument(Res.GetString(Res.ADP_InvalidSourceTable), parameter);
}
static internal Exception TablesAddNullAttempt(string parameter) {
return CollectionNullValue(parameter, typeof(DataTableMappingCollection), typeof(DataTableMapping));
}
static internal Exception TablesDataSetTable(string cacheTable) {
return CollectionIndexString(typeof(DataTableMapping), ADP.DataSetTable, cacheTable, typeof(DataTableMappingCollection));
}
static internal Exception TablesIndexInt32(int index, ITableMappingCollection collection) {
return CollectionIndexInt32(index, collection.GetType(), collection.Count);
}
static internal Exception TablesIsNotParent(ICollection collection) {
return ParametersIsNotParent(typeof(DataTableMapping), collection);
}
static internal Exception TablesIsParent(ICollection collection) {
return ParametersIsParent(typeof(DataTableMapping), collection);
}
static internal Exception TablesSourceIndex(string srcTable) {
return CollectionIndexString(typeof(DataTableMapping), ADP.SourceTable, srcTable, typeof(DataTableMappingCollection));
}
static internal Exception TablesUniqueSourceTable(string srcTable) {
return CollectionUniqueValue(typeof(DataTableMapping), ADP.SourceTable, srcTable);
}
static internal Exception NotADataTableMapping(object value) {
return CollectionInvalidType(typeof(DataTableMappingCollection), typeof(DataTableMapping), value);
}
//
// IDbCommand
//
static internal InvalidOperationException CommandAsyncOperationCompleted() {
return InvalidOperation(Res.GetString(Res.SQL_AsyncOperationCompleted));
}
static internal Exception CommandTextRequired(string method) {
return InvalidOperation(Res.GetString(Res.ADP_CommandTextRequired, method));
}
static internal InvalidOperationException ConnectionRequired(string method) {
return InvalidOperation(Res.GetString(Res.ADP_ConnectionRequired, method));
}
static internal InvalidOperationException OpenConnectionRequired(string method, ConnectionState state) {
return InvalidOperation(Res.GetString(Res.ADP_OpenConnectionRequired, method, ADP.ConnectionStateMsg(state)));
}
static internal InvalidOperationException UpdateConnectionRequired(StatementType statementType, bool isRowUpdatingCommand) {
string resource;
if (isRowUpdatingCommand) {
resource = Res.ADP_ConnectionRequired_Clone;
}
else {
switch(statementType) {
case StatementType.Insert:
resource = Res.ADP_ConnectionRequired_Insert;
break;
case StatementType.Update:
resource = Res.ADP_ConnectionRequired_Update;
break;
case StatementType.Delete:
resource = Res.ADP_ConnectionRequired_Delete;
break;
case StatementType.Batch:
resource = Res.ADP_ConnectionRequired_Batch;
goto default;
#if DEBUG
case StatementType.Select:
Debug.Assert(false, "shouldn't be here");
goto default;
#endif
default:
throw ADP.InvalidStatementType(statementType);
}
}
return InvalidOperation(Res.GetString(resource));
}
static internal InvalidOperationException ConnectionRequired_Res(string method) {
string resource = "ADP_ConnectionRequired_" + method;
#if DEBUG
switch(resource) {
case Res.ADP_ConnectionRequired_Fill:
case Res.ADP_ConnectionRequired_FillPage:
case Res.ADP_ConnectionRequired_FillSchema:
case Res.ADP_ConnectionRequired_Update:
case Res.ADP_ConnecitonRequired_UpdateRows:
break;
default:
Debug.Assert(false, "missing resource string: " + resource);
break;
}
#endif
return InvalidOperation(Res.GetString(resource));
}
static internal InvalidOperationException UpdateOpenConnectionRequired(StatementType statementType, bool isRowUpdatingCommand, ConnectionState state) {
string resource;
if (isRowUpdatingCommand) {
resource = Res.ADP_OpenConnectionRequired_Clone;
}
else {
switch(statementType) {
case StatementType.Insert:
resource = Res.ADP_OpenConnectionRequired_Insert;
break;
case StatementType.Update:
resource = Res.ADP_OpenConnectionRequired_Update;
break;
case StatementType.Delete:
resource = Res.ADP_OpenConnectionRequired_Delete;
break;
#if DEBUG
case StatementType.Select:
Debug.Assert(false, "shouldn't be here");
goto default;
case StatementType.Batch:
Debug.Assert(false, "isRowUpdatingCommand should have been true");
goto default;
#endif
default:
throw ADP.InvalidStatementType(statementType);
}
}
return InvalidOperation(Res.GetString(resource, ADP.ConnectionStateMsg(state)));
}
static internal Exception NoStoredProcedureExists(string sproc) {
return InvalidOperation(Res.GetString(Res.ADP_NoStoredProcedureExists, sproc));
}
static internal Exception OpenReaderExists() {
return OpenReaderExists(null);
}
static internal Exception OpenReaderExists(Exception e) {
return InvalidOperation(Res.GetString(Res.ADP_OpenReaderExists), e);
}
static internal Exception TransactionCompleted() {
return DataAdapter(Res.GetString(Res.ADP_TransactionCompleted));
}
//
// DbDataReader
//
static internal Exception NonSeqByteAccess(long badIndex, long currIndex, string method) {
return InvalidOperation(Res.GetString(Res.ADP_NonSeqByteAccess, badIndex.ToString(CultureInfo.InvariantCulture), currIndex.ToString(CultureInfo.InvariantCulture), method));
}
static internal Exception NegativeParameter(string parameterName) {
return InvalidOperation(Res.GetString(Res.ADP_NegativeParameter, parameterName));
}
static internal Exception NumericToDecimalOverflow() {
return InvalidCast(Res.GetString(Res.ADP_NumericToDecimalOverflow));
}
//
// Stream, SqlTypes, SqlClient
//
static internal Exception ExceedsMaxDataLength(long specifiedLength, long maxLength) {
return IndexOutOfRange(Res.GetString(Res.SQL_ExceedsMaxDataLength, specifiedLength.ToString(CultureInfo.InvariantCulture), maxLength.ToString(CultureInfo.InvariantCulture)));
}
static internal Exception InvalidSeekOrigin(string parameterName) {
return ArgumentOutOfRange(Res.GetString(Res.ADP_InvalidSeekOrigin), parameterName);
}
//
// SqlMetaData, SqlTypes, SqlClient
//
static internal Exception InvalidImplicitConversion(Type fromtype, string totype) {
return InvalidCast(Res.GetString(Res.ADP_InvalidImplicitConversion, fromtype.Name, totype));
}
static internal Exception InvalidMetaDataValue() {
return ADP.Argument(Res.GetString(Res.ADP_InvalidMetaDataValue));
}
static internal Exception NotRowType() {
return InvalidOperation(Res.GetString(Res.ADP_NotRowType));
}
//
// DbDataAdapter
//
static internal ArgumentException UnwantedStatementType(StatementType statementType) {
return Argument(Res.GetString(Res.ADP_UnwantedStatementType, statementType.ToString()));
}
static internal InvalidOperationException NonSequentialColumnAccess(int badCol, int currCol) {
return InvalidOperation(Res.GetString(Res.ADP_NonSequentialColumnAccess, badCol.ToString(CultureInfo.InvariantCulture), currCol.ToString(CultureInfo.InvariantCulture)));
}
//
// DbDataAdapter.FillSchema
//
static internal Exception FillSchemaRequiresSourceTableName(string parameter) {
return Argument(Res.GetString(Res.ADP_FillSchemaRequiresSourceTableName), parameter);
}
//
// DbDataAdapter.Fill
//
static internal Exception InvalidMaxRecords(string parameter, int max) {
return Argument(Res.GetString(Res.ADP_InvalidMaxRecords, max.ToString(CultureInfo.InvariantCulture)), parameter);
}
static internal Exception InvalidStartRecord(string parameter, int start) {
return Argument(Res.GetString(Res.ADP_InvalidStartRecord, start.ToString(CultureInfo.InvariantCulture)), parameter);
}
static internal Exception FillRequires(string parameter) {
return ArgumentNull(parameter);
}
static internal Exception FillRequiresSourceTableName(string parameter) {
return Argument(Res.GetString(Res.ADP_FillRequiresSourceTableName), parameter);
}
static internal Exception FillChapterAutoIncrement() {
return InvalidOperation(Res.GetString(Res.ADP_FillChapterAutoIncrement));
}
static internal InvalidOperationException MissingDataReaderFieldType(int index) {
return DataAdapter(Res.GetString(Res.ADP_MissingDataReaderFieldType, index));
}
static internal InvalidOperationException OnlyOneTableForStartRecordOrMaxRecords() {
return DataAdapter(Res.GetString(Res.ADP_OnlyOneTableForStartRecordOrMaxRecords));
}
//
// DbDataAdapter.Update
//
static internal ArgumentNullException UpdateRequiresNonNullDataSet(string parameter) {
return ArgumentNull(parameter);
}
static internal InvalidOperationException UpdateRequiresSourceTable(string defaultSrcTableName) {
return InvalidOperation(Res.GetString(Res.ADP_UpdateRequiresSourceTable, defaultSrcTableName));
}
static internal InvalidOperationException UpdateRequiresSourceTableName(string srcTable) {
return InvalidOperation(Res.GetString(Res.ADP_UpdateRequiresSourceTableName, srcTable)); // MDAC 70448
}
static internal ArgumentNullException UpdateRequiresDataTable(string parameter) {
return ArgumentNull(parameter);
}
static internal Exception UpdateConcurrencyViolation(StatementType statementType, int affected, int expected, DataRow[] dataRows) {
string resource;
switch(statementType) {
case StatementType.Update:
resource = Res.ADP_UpdateConcurrencyViolation_Update;
break;
case StatementType.Delete:
resource = Res.ADP_UpdateConcurrencyViolation_Delete;
break;
case StatementType.Batch:
resource = Res.ADP_UpdateConcurrencyViolation_Batch;
break;
#if DEBUG
case StatementType.Select:
case StatementType.Insert:
Debug.Assert(false, "should be here");
goto default;
#endif
default:
throw ADP.InvalidStatementType(statementType);
}
DBConcurrencyException exception = new DBConcurrencyException(Res.GetString(resource, affected.ToString(CultureInfo.InvariantCulture), expected.ToString(CultureInfo.InvariantCulture)), null, dataRows);
TraceExceptionAsReturnValue(exception);
return exception;
}
static internal InvalidOperationException UpdateRequiresCommand(StatementType statementType, bool isRowUpdatingCommand) {
string resource;
if (isRowUpdatingCommand) {
resource = Res.ADP_UpdateRequiresCommandClone;
}
else {
switch(statementType) {
case StatementType.Select:
resource = Res.ADP_UpdateRequiresCommandSelect;
break;
case StatementType.Insert:
resource = Res.ADP_UpdateRequiresCommandInsert;
break;
case StatementType.Update:
resource = Res.ADP_UpdateRequiresCommandUpdate;
break;
case StatementType.Delete:
resource = Res.ADP_UpdateRequiresCommandDelete;
break;
#if DEBUG
case StatementType.Batch:
Debug.Assert(false, "isRowUpdatingCommand should have been true");
goto default;
#endif
default:
throw ADP.InvalidStatementType(statementType);
}
}
return InvalidOperation(Res.GetString(resource));
}
static internal ArgumentException UpdateMismatchRowTable(int i) {
return Argument(Res.GetString(Res.ADP_UpdateMismatchRowTable, i.ToString(CultureInfo.InvariantCulture)));
}
static internal DataException RowUpdatedErrors() {
return Data(Res.GetString(Res.ADP_RowUpdatedErrors));
}
static internal DataException RowUpdatingErrors() {
return Data(Res.GetString(Res.ADP_RowUpdatingErrors));
}
static internal InvalidOperationException ResultsNotAllowedDuringBatch() {
return DataAdapter(Res.GetString(Res.ADP_ResultsNotAllowedDuringBatch));
}
//
// : IDbCommand
//
static internal Exception InvalidCommandTimeout(int value) {
return Argument(Res.GetString(Res.ADP_InvalidCommandTimeout, value.ToString(CultureInfo.InvariantCulture)), ADP.CommandTimeout);
}
static internal Exception DeriveParametersNotSupported(IDbCommand value) {
return DataAdapter(Res.GetString(Res.ADP_DeriveParametersNotSupported, value.GetType().Name, value.CommandType.ToString()));
}
static internal Exception UninitializedParameterSize(int index, Type dataType) {
return InvalidOperation(Res.GetString(Res.ADP_UninitializedParameterSize, index.ToString(CultureInfo.InvariantCulture), dataType.Name));
}
static internal Exception PrepareParameterType(IDbCommand cmd) {
return InvalidOperation(Res.GetString(Res.ADP_PrepareParameterType, cmd.GetType().Name));
}
static internal Exception PrepareParameterSize(IDbCommand cmd) {
return InvalidOperation(Res.GetString(Res.ADP_PrepareParameterSize, cmd.GetType().Name));
}
static internal Exception PrepareParameterScale(IDbCommand cmd, string type) {
return InvalidOperation(Res.GetString(Res.ADP_PrepareParameterScale, cmd.GetType().Name, type));
}
static internal Exception MismatchedAsyncResult(string expectedMethod, string gotMethod) {
return InvalidOperation(Res.GetString(Res.ADP_MismatchedAsyncResult, expectedMethod, gotMethod));
}
//
// : ConnectionUtil
//
static internal Exception ConnectionIsDisabled (Exception InnerException) {
return InvalidOperation(Res.GetString(Res.ADP_ConnectionIsDisabled), InnerException);
}
static internal Exception ClosedConnectionError() {
return InvalidOperation(Res.GetString(Res.ADP_ClosedConnectionError));
}
static internal Exception ConnectionAlreadyOpen(ConnectionState state) {
return InvalidOperation(Res.GetString(Res.ADP_ConnectionAlreadyOpen, ADP.ConnectionStateMsg(state)));
}
static internal Exception DelegatedTransactionPresent() {
return InvalidOperation(Res.GetString(Res.ADP_DelegatedTransactionPresent));
}
static internal Exception TransactionPresent() {
return InvalidOperation(Res.GetString(Res.ADP_TransactionPresent));
}
static internal Exception LocalTransactionPresent() {
return InvalidOperation(Res.GetString(Res.ADP_LocalTransactionPresent));
}
static internal Exception OpenConnectionPropertySet(string property, ConnectionState state) {
return InvalidOperation(Res.GetString(Res.ADP_OpenConnectionPropertySet, property, ADP.ConnectionStateMsg(state)));
}
static internal Exception EmptyDatabaseName() {
return Argument(Res.GetString(Res.ADP_EmptyDatabaseName));
}
static internal Exception DatabaseNameTooLong() {
return Argument(Res.GetString(Res.ADP_DatabaseNameTooLong));
}
internal enum ConnectionError {
BeginGetConnectionReturnsNull,
GetConnectionReturnsNull,
ConnectionOptionsMissing,
CouldNotSwitchToClosedPreviouslyOpenedState,
}
static internal Exception InternalConnectionError(ConnectionError internalError) {
return InvalidOperation(Res.GetString(Res.ADP_InternalConnectionError, (int)internalError));
}
internal enum InternalErrorCode {
UnpooledObjectHasOwner = 0,
UnpooledObjectHasWrongOwner = 1,
PushingObjectSecondTime = 2,
PooledObjectHasOwner = 3,
PooledObjectInPoolMoreThanOnce = 4,
CreateObjectReturnedNull = 5,
NewObjectCannotBePooled = 6,
NonPooledObjectUsedMoreThanOnce = 7,
AttemptingToPoolOnRestrictedToken = 8,
// ConnectionOptionsInUse = 9,
ConvertSidToStringSidWReturnedNull = 10,
// UnexpectedTransactedObject = 11,
AttemptingToConstructReferenceCollectionOnStaticObject = 12,
AttemptingToEnlistTwice = 13,
CreateReferenceCollectionReturnedNull = 14,
PooledObjectWithoutPool = 15,
UnexpectedWaitAnyResult = 16,
SynchronousConnectReturnedPending = 17,
CompletedConnectReturnedPending = 18,
NameValuePairNext = 20,
InvalidParserState1 = 21,
InvalidParserState2 = 22,
InvalidParserState3 = 23,
InvalidBuffer = 30,
UnimplementedSMIMethod = 40,
InvalidSmiCall = 41,
SqlDependencyObtainProcessDispatcherFailureObjectHandle = 50,
SqlDependencyProcessDispatcherFailureCreateInstance = 51,
SqlDependencyProcessDispatcherFailureAppDomain = 52,
SqlDependencyCommandHashIsNotAssociatedWithNotification = 53,
UnknownTransactionFailure = 60,
}
static internal Exception InternalError(InternalErrorCode internalError) {
return InvalidOperation(Res.GetString(Res.ADP_InternalProviderError, (int)internalError));
}
static internal Exception InternalError(InternalErrorCode internalError, Exception innerException) {
return InvalidOperation(Res.GetString(Res.ADP_InternalProviderError, (int)internalError), innerException);
}
static internal Exception InvalidConnectTimeoutValue() {
return Argument(Res.GetString(Res.ADP_InvalidConnectTimeoutValue));
}
static internal Exception InvalidConnectRetryCountValue() {
return Argument(Res.GetString(Res.SQLCR_InvalidConnectRetryCountValue));
}
static internal Exception InvalidConnectRetryIntervalValue() {
return Argument(Res.GetString(Res.SQLCR_InvalidConnectRetryIntervalValue));
}
//
// : DbDataReader
//
static internal Exception DataReaderNoData() {
return InvalidOperation(Res.GetString(Res.ADP_DataReaderNoData));
}
static internal Exception DataReaderClosed(string method) {
return InvalidOperation(Res.GetString(Res.ADP_DataReaderClosed, method));
}
static internal ArgumentOutOfRangeException InvalidSourceBufferIndex(int maxLen, long srcOffset, string parameterName) {
return ArgumentOutOfRange(Res.GetString(Res.ADP_InvalidSourceBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), srcOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
}
static internal ArgumentOutOfRangeException InvalidDestinationBufferIndex(int maxLen, int dstOffset, string parameterName) {
return ArgumentOutOfRange(Res.GetString(Res.ADP_InvalidDestinationBufferIndex, maxLen.ToString(CultureInfo.InvariantCulture), dstOffset.ToString(CultureInfo.InvariantCulture)), parameterName);
}
static internal IndexOutOfRangeException InvalidBufferSizeOrIndex(int numBytes, int bufferIndex) {
return IndexOutOfRange(Res.GetString(Res.SQL_InvalidBufferSizeOrIndex, numBytes.ToString(CultureInfo.InvariantCulture), bufferIndex.ToString(CultureInfo.InvariantCulture)));
}
static internal Exception InvalidDataLength(long length) {
return IndexOutOfRange(Res.GetString(Res.SQL_InvalidDataLength, length.ToString(CultureInfo.InvariantCulture)));
}
static internal InvalidOperationException AsyncOperationPending() {
return InvalidOperation(Res.GetString(Res.ADP_PendingAsyncOperation));
}
//
// : Stream
//
static internal Exception StreamClosed(string method) {
return InvalidOperation(Res.GetString(Res.ADP_StreamClosed, method));
}
static internal IOException ErrorReadingFromStream(Exception internalException) {
return IO(Res.GetString(Res.SqlMisc_StreamErrorMessage), internalException);
}
//
// : DbDataAdapter
//
static internal InvalidOperationException DynamicSQLJoinUnsupported() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLJoinUnsupported));
}
static internal InvalidOperationException DynamicSQLNoTableInfo() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNoTableInfo));
}
static internal InvalidOperationException DynamicSQLNoKeyInfoDelete() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNoKeyInfoDelete));
}
static internal InvalidOperationException DynamicSQLNoKeyInfoUpdate() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNoKeyInfoUpdate));
}
static internal InvalidOperationException DynamicSQLNoKeyInfoRowVersionDelete() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNoKeyInfoRowVersionDelete));
}
static internal InvalidOperationException DynamicSQLNoKeyInfoRowVersionUpdate() {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNoKeyInfoRowVersionUpdate));
}
static internal InvalidOperationException DynamicSQLNestedQuote(string name, string quote) {
return InvalidOperation(Res.GetString(Res.ADP_DynamicSQLNestedQuote, name, quote));
}
static internal InvalidOperationException NoQuoteChange() {
return InvalidOperation(Res.GetString(Res.ADP_NoQuoteChange));
}
static internal InvalidOperationException ComputerNameEx(int lastError) {
return InvalidOperation(Res.GetString(Res.ADP_ComputerNameEx, lastError));
}
static internal InvalidOperationException MissingSourceCommand() {
return InvalidOperation(Res.GetString(Res.ADP_MissingSourceCommand));
}
static internal InvalidOperationException MissingSourceCommandConnection() {
return InvalidOperation(Res.GetString(Res.ADP_MissingSourceCommandConnection));
}
//
// : IDataParameter
//
static internal ArgumentException InvalidDataType(TypeCode typecode) {
return Argument(Res.GetString(Res.ADP_InvalidDataType, typecode.ToString()));
}
static internal ArgumentException UnknownDataType(Type dataType) {
return Argument(Res.GetString(Res.ADP_UnknownDataType, dataType.FullName));
}
static internal ArgumentException DbTypeNotSupported(System.Data.DbType type, Type enumtype) {
return Argument(Res.GetString(Res.ADP_DbTypeNotSupported, type.ToString(), enumtype.Name));
}
static internal ArgumentException UnknownDataTypeCode(Type dataType, TypeCode typeCode) {
return Argument(Res.GetString(Res.ADP_UnknownDataTypeCode, ((int) typeCode).ToString(CultureInfo.InvariantCulture), dataType.FullName));
}
static internal ArgumentException InvalidOffsetValue(int value) {
return Argument(Res.GetString(Res.ADP_InvalidOffsetValue, value.ToString(CultureInfo.InvariantCulture)));
}
static internal ArgumentException InvalidSizeValue(int value) {
return Argument(Res.GetString(Res.ADP_InvalidSizeValue, value.ToString(CultureInfo.InvariantCulture)));
}
static internal ArgumentException ParameterValueOutOfRange(Decimal value) {
return ADP.Argument(Res.GetString(Res.ADP_ParameterValueOutOfRange, value.ToString((IFormatProvider)null)));
}
static internal ArgumentException ParameterValueOutOfRange(SqlDecimal value) {
return ADP.Argument(Res.GetString(Res.ADP_ParameterValueOutOfRange, value.ToString()));
}
static internal ArgumentException ParameterValueOutOfRange(String value) {
return ADP.Argument(Res.GetString(Res.ADP_ParameterValueOutOfRange, value));
}
static internal ArgumentException VersionDoesNotSupportDataType(string typeName) {
return Argument(Res.GetString(Res.ADP_VersionDoesNotSupportDataType, typeName));
}
static internal Exception ParameterConversionFailed(object value, Type destType, Exception inner) { // WebData 75433
Debug.Assert(null != value, "null value on conversion failure");
Debug.Assert(null != inner, "null inner on conversion failure");
Exception e;
string message = Res.GetString(Res.ADP_ParameterConversionFailed, value.GetType().Name, destType.Name);
if (inner is ArgumentException) {
e = new ArgumentException(message, inner);
}
else if (inner is FormatException) {
e = new FormatException(message, inner);
}
else if (inner is InvalidCastException) {
e = new InvalidCastException(message, inner);
}
else if (inner is OverflowException) {
e = new OverflowException(message, inner);
}
else {
e = inner;
}
TraceExceptionAsReturnValue(e);
return e;
}
//
// : IDataParameterCollection
//
static internal Exception ParametersMappingIndex(int index, IDataParameterCollection collection) {
return CollectionIndexInt32(index, collection.GetType(), collection.Count);
}
static internal Exception ParametersSourceIndex(string parameterName, IDataParameterCollection collection, Type parameterType) {
return CollectionIndexString(parameterType, ADP.ParameterName, parameterName, collection.GetType());
}
static internal Exception ParameterNull(string parameter, IDataParameterCollection collection, Type parameterType) {
return CollectionNullValue(parameter, collection.GetType(), parameterType);
}
static internal Exception InvalidParameterType(IDataParameterCollection collection, Type parameterType, object invalidValue) {
return CollectionInvalidType(collection.GetType(), parameterType, invalidValue);
}
//
// : IDbTransaction
//
static internal Exception ParallelTransactionsNotSupported(IDbConnection obj) {
return InvalidOperation(Res.GetString(Res.ADP_ParallelTransactionsNotSupported, obj.GetType().Name));
}
static internal Exception TransactionZombied(IDbTransaction obj) {
return InvalidOperation(Res.GetString(Res.ADP_TransactionZombied, obj.GetType().Name));
}
static internal Exception DbRecordReadOnly(string methodname) {
return InvalidOperation(Res.GetString(Res.ADP_DbRecordReadOnly, methodname));
}
static internal Exception OffsetOutOfRangeException() {
return InvalidOperation(Res.GetString(Res.ADP_OffsetOutOfRangeException));
}
//
// : DbMetaDataFactory
//
static internal Exception AmbigousCollectionName(string collectionName) {
return Argument(Res.GetString(Res.MDF_AmbigousCollectionName,collectionName));
}
static internal Exception CollectionNameIsNotUnique(string collectionName) {
return Argument(Res.GetString(Res.MDF_CollectionNameISNotUnique,collectionName));
}
static internal Exception DataTableDoesNotExist(string collectionName) {
return Argument(Res.GetString(Res.MDF_DataTableDoesNotExist,collectionName));
}
static internal Exception IncorrectNumberOfDataSourceInformationRows() {
return Argument(Res.GetString(Res.MDF_IncorrectNumberOfDataSourceInformationRows));
}
static internal ArgumentException InvalidRestrictionValue(string collectionName, string restrictionName, string restrictionValue) {
return ADP.Argument(Res.GetString(Res.MDF_InvalidRestrictionValue, collectionName, restrictionName, restrictionValue));
}
static internal Exception InvalidXml() {
return Argument(Res.GetString(Res.MDF_InvalidXml));
}
static internal Exception InvalidXmlMissingColumn(string collectionName, string columnName) {
return Argument(Res.GetString(Res.MDF_InvalidXmlMissingColumn, collectionName, columnName));
}
static internal Exception InvalidXmlInvalidValue(string collectionName, string columnName) {
return Argument(Res.GetString(Res.MDF_InvalidXmlInvalidValue, collectionName, columnName));
}
static internal Exception MissingDataSourceInformationColumn() {
return Argument(Res.GetString(Res.MDF_MissingDataSourceInformationColumn));
}
static internal Exception MissingRestrictionColumn() {
return Argument(Res.GetString(Res.MDF_MissingRestrictionColumn));
}
static internal Exception MissingRestrictionRow() {
return Argument(Res.GetString(Res.MDF_MissingRestrictionRow));
}
static internal Exception NoColumns() {
return Argument(Res.GetString(Res.MDF_NoColumns));
}
static internal Exception QueryFailed(string collectionName, Exception e) {
return InvalidOperation(Res.GetString(Res.MDF_QueryFailed,collectionName), e);
}
static internal Exception TooManyRestrictions(string collectionName) {
return Argument(Res.GetString(Res.MDF_TooManyRestrictions,collectionName));
}
static internal Exception UnableToBuildCollection(string collectionName) {
return Argument(Res.GetString(Res.MDF_UnableToBuildCollection,collectionName));
}
static internal Exception UndefinedCollection(string collectionName) {
return Argument(Res.GetString(Res.MDF_UndefinedCollection,collectionName));
}
static internal Exception UndefinedPopulationMechanism(string populationMechanism) {
return Argument(Res.GetString(Res.MDF_UndefinedPopulationMechanism,populationMechanism));
}
static internal Exception UnsupportedVersion(string collectionName) {
return Argument(Res.GetString(Res.MDF_UnsupportedVersion,collectionName));
}
//
// : CommandBuilder
//
static internal InvalidOperationException InvalidDateTimeDigits(string dataTypeName) {
return InvalidOperation(Res.GetString(Res.ADP_InvalidDateTimeDigits, dataTypeName));
}
static internal Exception InvalidFormatValue() {
return Argument(Res.GetString(Res.ADP_InvalidFormatValue));
}
static internal InvalidOperationException InvalidMaximumScale(string dataTypeName) {
return InvalidOperation(Res.GetString(Res.ADP_InvalidMaximumScale, dataTypeName));
}
static internal Exception LiteralValueIsInvalid(string dataTypeName){
return Argument(Res.GetString(Res.ADP_LiteralValueIsInvalid,dataTypeName));
}
static internal Exception EvenLengthLiteralValue(string argumentName) {
return Argument(Res.GetString(Res.ADP_EvenLengthLiteralValue), argumentName );
}
static internal Exception HexDigitLiteralValue(string argumentName) {
return Argument(Res.GetString(Res.ADP_HexDigitLiteralValue), argumentName );
}
static internal InvalidOperationException QuotePrefixNotSet(string method) {
return InvalidOperation(Res.GetString(Res.ADP_QuotePrefixNotSet, method));
}
static internal InvalidOperationException UnableToCreateBooleanLiteral() {
return ADP.InvalidOperation(Res.GetString(Res.ADP_UnableToCreateBooleanLiteral));
}
static internal Exception UnsupportedNativeDataTypeOleDb(string dataTypeName) {
return Argument(Res.GetString(Res.ADP_UnsupportedNativeDataTypeOleDb, dataTypeName));
}
// Sql Result Set and other generic message
static internal Exception InvalidArgumentValue(string methodName) {
return Argument(Res.GetString(Res.ADP_InvalidArgumentValue, methodName));
}
// global constant strings
internal const string Append = "Append";
internal const string BeginExecuteNonQuery = "BeginExecuteNonQuery";
internal const string BeginExecuteReader = "BeginExecuteReader";
internal const string BeginTransaction = "BeginTransaction";
internal const string BeginExecuteXmlReader = "BeginExecuteXmlReader";
internal const string ChangeDatabase = "ChangeDatabase";
internal const string Cancel = "Cancel";
internal const string Clone = "Clone";
internal const string ColumnEncryptionSystemProviderNamePrefix = "MSSQL_";
internal const string CommitTransaction = "CommitTransaction";
internal const string CommandTimeout = "CommandTimeout";
internal const string ConnectionString = "ConnectionString";
internal const string DataSetColumn = "DataSetColumn";
internal const string DataSetTable = "DataSetTable";
internal const string Delete = "Delete";
internal const string DeleteCommand = "DeleteCommand";
internal const string DeriveParameters = "DeriveParameters";
internal const string EndExecuteNonQuery = "EndExecuteNonQuery";
internal const string EndExecuteReader = "EndExecuteReader";
internal const string EndExecuteXmlReader = "EndExecuteXmlReader";
internal const string ExecuteReader = "ExecuteReader";
internal const string ExecuteRow = "ExecuteRow";
internal const string ExecuteNonQuery = "ExecuteNonQuery";
internal const string ExecuteScalar = "ExecuteScalar";
internal const string ExecuteSqlScalar = "ExecuteSqlScalar";
internal const string ExecuteXmlReader = "ExecuteXmlReader";
internal const string Fill = "Fill";
internal const string FillPage = "FillPage";
internal const string FillSchema = "FillSchema";
internal const string GetBytes = "GetBytes";
internal const string GetChars = "GetChars";
internal const string GetOleDbSchemaTable = "GetOleDbSchemaTable";
internal const string GetProperties = "GetProperties";
internal const string GetSchema = "GetSchema";
internal const string GetSchemaTable = "GetSchemaTable";
internal const string GetServerTransactionLevel = "GetServerTransactionLevel";
internal const string Insert = "Insert";
internal const string Open = "Open";
internal const string Parameter = "Parameter";
internal const string ParameterBuffer = "buffer";
internal const string ParameterCount = "count";
internal const string ParameterDestinationType = "destinationType";
internal const string ParameterIndex = "index";
internal const string ParameterName = "ParameterName";
internal const string ParameterOffset = "offset";
internal const string ParameterSetPosition = "set_Position";
internal const string ParameterService = "Service";
internal const string ParameterTimeout = "Timeout";
internal const string ParameterUserData = "UserData";
internal const string Prepare = "Prepare";
internal const string QuoteIdentifier = "QuoteIdentifier";
internal const string Read = "Read";
internal const string ReadAsync = "ReadAsync";
internal const string Remove = "Remove";
internal const string RollbackTransaction = "RollbackTransaction";
internal const string SaveTransaction = "SaveTransaction";
internal const string SetProperties = "SetProperties";
internal const string SourceColumn = "SourceColumn";
internal const string SourceVersion = "SourceVersion";
internal const string SourceTable = "SourceTable";
internal const string UnquoteIdentifier = "UnquoteIdentifier";
internal const string Update = "Update";
internal const string UpdateCommand = "UpdateCommand";
internal const string UpdateRows = "UpdateRows";
internal const CompareOptions compareOptions = CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase;
internal const int DecimalMaxPrecision = 29;
internal const int DecimalMaxPrecision28 = 28; // there are some cases in Odbc where we need that ...
internal const int DefaultCommandTimeout = 30;
internal const int DefaultConnectionTimeout = DbConnectionStringDefaults.ConnectTimeout;
internal const float FailoverTimeoutStep = 0.08F; // fraction of timeout to use for fast failover connections
internal const float FailoverTimeoutStepForTnir = 0.125F; // Fraction of timeout to use in case of Transparent Network IP resolution.
internal const int MinimumTimeoutForTnirMs = 500; // The first login attempt in Transparent network IP Resolution
// security issue, don't rely upon static public readonly values - AS/URT 109635
static internal readonly String StrEmpty = ""; // String.Empty
static internal readonly IntPtr PtrZero = new IntPtr(0); // IntPtr.Zero
static internal readonly int PtrSize = IntPtr.Size;
static internal readonly IntPtr InvalidPtr = new IntPtr(-1); // use for INVALID_HANDLE
static internal readonly IntPtr RecordsUnaffected = new IntPtr(-1);
static internal readonly HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
internal const int CharSize = System.Text.UnicodeEncoding.CharSize;
static internal bool CompareInsensitiveInvariant(string strvalue, string strconst) {
return (0 == CultureInfo.InvariantCulture.CompareInfo.Compare(strvalue, strconst, CompareOptions.IgnoreCase));
}
static internal Delegate FindBuilder(MulticastDelegate mcd) { // V1.2.3300
if (null != mcd) {
Delegate[] d = mcd.GetInvocationList();
for (int i = 0; i < d.Length; i++) {
if (d[i].Target is DbCommandBuilder)
return d[i];
}
}
return null;
}
static internal readonly bool IsWindowsNT = (PlatformID.Win32NT == Environment.OSVersion.Platform);
static internal readonly bool IsPlatformNT5 = (ADP.IsWindowsNT && (Environment.OSVersion.Version.Major >= 5));
static internal SysTx.Transaction GetCurrentTransaction() {
SysTx.Transaction transaction = SysTx.Transaction.Current;
return transaction;
}
static internal void SetCurrentTransaction(SysTx.Transaction transaction)
{
SysTx.Transaction.Current = transaction;
}
static internal SysTx.IDtcTransaction GetOletxTransaction(SysTx.Transaction transaction){
SysTx.IDtcTransaction oleTxTransaction = null;
if (null != transaction) {
oleTxTransaction = SysTx.TransactionInterop.GetDtcTransaction(transaction);
}
return oleTxTransaction;
}
[System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
static internal bool IsSysTxEqualSysEsTransaction() {
#if MOBILE
return false;
#else
// This Method won't JIT inproc (ES isn't available), so we code it
// separately and call it behind an if statement.
bool result = (!SysES.ContextUtil.IsInTransaction && null == SysTx.Transaction.Current)
|| (SysES.ContextUtil.IsInTransaction && SysTx.Transaction.Current == (SysTx.Transaction)SysES.ContextUtil.SystemTransaction);
return result;
#endif
}
static internal bool NeedManualEnlistment() {
#if !MOBILE && !MONO_PARTIAL_DATA_IMPORT
// We need to force a manual enlistment of transactions for ODBC and
// OLEDB whenever the current SysTx transaction != the SysTx transaction
// on the EnterpriseServices ContextUtil, or when ES.ContextUtil is
// not available and there is a non-null current SysTx transaction.
if (IsWindowsNT) { // we can reference SysTx just not use it on Win9X, we can't ever reference SysES on Win9X
bool isEnterpriseServicesOK = !InOutOfProcHelper.InProc;
if ((isEnterpriseServicesOK && !IsSysTxEqualSysEsTransaction())
|| (!isEnterpriseServicesOK && null != SysTx.Transaction.Current)) {
return true;
}
}
#endif
return false;
}
static internal void TimerCurrent(out long ticks) {
ticks = DateTime.UtcNow.ToFileTimeUtc();
}
static internal long TimerCurrent() {
return DateTime.UtcNow.ToFileTimeUtc();
}
static internal long TimerFromSeconds(int seconds) {
long result = checked((long)seconds * TimeSpan.TicksPerSecond);
return result;
}
static internal long TimerFromMilliseconds(long milliseconds) {
long result = checked(milliseconds * TimeSpan.TicksPerMillisecond);
return result;
}
static internal bool TimerHasExpired(long timerExpire) {
bool result = TimerCurrent() > timerExpire;
return result;
}
static internal long TimerRemaining(long timerExpire) {
long timerNow = TimerCurrent();
long result = checked(timerExpire - timerNow);
return result;
}
static internal long TimerRemainingMilliseconds(long timerExpire) {
long result = TimerToMilliseconds(TimerRemaining(timerExpire));
return result;
}
static internal long TimerRemainingSeconds(long timerExpire) {
long result = TimerToSeconds(TimerRemaining(timerExpire));
return result;
}
static internal long TimerToMilliseconds(long timerValue) {
long result = timerValue / TimeSpan.TicksPerMillisecond;
return result;
}
static private long TimerToSeconds(long timerValue) {
long result = timerValue / TimeSpan.TicksPerSecond;
return result;
}
[EnvironmentPermission(SecurityAction.Assert, Read = "COMPUTERNAME")]
static internal string MachineName()
{
// Note: In Longhorn you'll be able to rename a machine without
// rebooting. Therefore, don't cache this machine name.
return Environment.MachineName;
}
static internal string BuildQuotedString(string quotePrefix, string quoteSuffix, string unQuotedString) {
StringBuilder resultString = new StringBuilder();
if (ADP.IsEmpty(quotePrefix) == false) {
resultString.Append(quotePrefix);
}
// Assuming that the suffix is escaped by doubling it. i.e. foo"bar becomes "foo""bar".
if (ADP.IsEmpty(quoteSuffix) == false) {
resultString.Append(unQuotedString.Replace(quoteSuffix,quoteSuffix+quoteSuffix));
resultString.Append(quoteSuffix);
}
else {
resultString.Append(unQuotedString);
}
return resultString.ToString();
}
private const string hexDigits = "0123456789abcdef";
static internal byte[] ByteArrayFromString(string hexString, string dataTypeName) {
if ((hexString.Length & 0x1) != 0) {
throw ADP.LiteralValueIsInvalid(dataTypeName);
}
char[] c = hexString.ToCharArray();
byte[] b = new byte[hexString.Length / 2];
CultureInfo invariant = CultureInfo.InvariantCulture;
for (int i = 0; i < hexString.Length; i += 2) {
int h = hexDigits.IndexOf(Char.ToLower(c[i], invariant));
int l = hexDigits.IndexOf(Char.ToLower(c[i+1], invariant));
if (h < 0 || l < 0) {
throw ADP.LiteralValueIsInvalid(dataTypeName);
}
b[i/2] = (byte)((h << 4) | l);
}
return b;
}
static internal void EscapeSpecialCharacters(string unescapedString, StringBuilder escapedString){
// note special characters list is from character escapes
// in the MSDN regular expression language elements documentation
// added ] since escaping it seems necessary
const string specialCharacters = ".$^{[(|)*+?\\]";
foreach (char currentChar in unescapedString){
if (specialCharacters.IndexOf(currentChar) >= 0) {
escapedString.Append("\\");
}
escapedString.Append(currentChar);
}
return;
}
static internal string FixUpDecimalSeparator(string numericString,
Boolean formatLiteral,
string decimalSeparator,
char[] exponentSymbols) {
String returnString;
// don't replace the decimal separator if the string is in exponent format
if (numericString.IndexOfAny(exponentSymbols) == -1){
// if the user has set a decimal separator use it, if not use the current culture's value
if (ADP.IsEmpty(decimalSeparator) == true) {
decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
}
if (formatLiteral == true){
returnString = numericString.Replace(".",decimalSeparator);
}
else {
returnString = numericString.Replace(decimalSeparator,".");
}
}
else {
returnString = numericString;
}
return returnString;
}
[FileIOPermission(SecurityAction.Assert, AllFiles=FileIOPermissionAccess.PathDiscovery)]
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal string GetFullPath(string filename) { // MDAC 77686
return Path.GetFullPath(filename);
}
//
static internal string GetComputerNameDnsFullyQualified() {
const int ComputerNameDnsFullyQualified = 3; // winbase.h, enum COMPUTER_NAME_FORMAT
const int ERROR_MORE_DATA = 234; // winerror.h
string value;
#if MOBILE
value = ADP.MachineName();
#else
if (IsPlatformNT5) {
int length = 0; // length parameter must be zero if buffer is null
// query for the required length
// VSTFDEVDIV 479551 - ensure that GetComputerNameEx does not fail with unexpected values and that the length is positive
int getComputerNameExError = 0;
if (0 == SafeNativeMethods.GetComputerNameEx(ComputerNameDnsFullyQualified, null, ref length)) {
getComputerNameExError = Marshal.GetLastWin32Error();
}
if ((getComputerNameExError != 0 && getComputerNameExError != ERROR_MORE_DATA) || length <= 0) {
throw ADP.ComputerNameEx(getComputerNameExError);
}
StringBuilder buffer = new StringBuilder(length);
length = buffer.Capacity;
if (0 == SafeNativeMethods.GetComputerNameEx(ComputerNameDnsFullyQualified, buffer, ref length)) {
throw ADP.ComputerNameEx(Marshal.GetLastWin32Error());
}
// Note: In Longhorn you'll be able to rename a machine without
// rebooting. Therefore, don't cache this machine name.
value = buffer.ToString();
}
else {
value = ADP.MachineName();
}
#endif
return value;
}
// SxS: the file is opened in FileShare.Read mode allowing several threads/apps to read it simultaneously
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal Stream GetFileStream(string filename) {
#if MONO_FEATURE_CAS
(new FileIOPermission(FileIOPermissionAccess.Read, filename)).Assert();
try {
return new FileStream(filename,FileMode.Open,FileAccess.Read,FileShare.Read);
}
finally {
FileIOPermission.RevertAssert();
}
#else
return new FileStream(filename,FileMode.Open,FileAccess.Read,FileShare.Read);
#endif
}
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal FileVersionInfo GetVersionInfo(string filename) {
#if MONO_FEATURE_CAS
(new FileIOPermission(FileIOPermissionAccess.Read, filename)).Assert(); // MDAC 62038
try {
return FileVersionInfo.GetVersionInfo(filename); // MDAC 60411
}
finally {
FileIOPermission.RevertAssert();
}
#else
return FileVersionInfo.GetVersionInfo(filename); // MDAC 60411
#endif
}
#if MOBILE
static internal object LocalMachineRegistryValue(string subkey, string queryvalue) {
return null;
}
#else
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal Stream GetXmlStreamFromValues(String[] values, String errorString) {
if (values.Length != 1){
throw ADP.ConfigWrongNumberOfValues(errorString);
}
return ADP.GetXmlStream(values[0],errorString);
}
// SxS (VSDD 545786): metadata files are opened from <.NetRuntimeFolder>\CONFIG\<metadatafilename.xml>
// this operation is safe in SxS because the file is opened in read-only mode and each NDP runtime accesses its own copy of the metadata
// under the runtime folder.
// This method returns stream to open file, so its ResourceExposure value is ResourceScope.Machine.
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal Stream GetXmlStream(String value, String errorString) {
Stream XmlStream;
const string config = "config\\";
// get location of config directory
string rootPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
if (rootPath == null) {
throw ADP.ConfigUnableToLoadXmlMetaDataFile(errorString);
}
StringBuilder tempstring = new StringBuilder(rootPath.Length+config.Length+value.Length);
tempstring.Append(rootPath);
tempstring.Append(config);
tempstring.Append(value);
String fullPath = tempstring.ToString();
// don't allow relative paths
if (ADP.GetFullPath(fullPath) != fullPath) {
throw ADP.ConfigUnableToLoadXmlMetaDataFile(errorString);
}
try {
XmlStream = ADP.GetFileStream(fullPath);
}
catch(Exception e){
//
if (!ADP.IsCatchableExceptionType(e)) {
throw;
}
throw ADP.ConfigUnableToLoadXmlMetaDataFile(errorString);
}
return XmlStream;
}
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal object ClassesRootRegistryValue(string subkey, string queryvalue) { // MDAC 77697
(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_CLASSES_ROOT\\" + subkey)).Assert(); // MDAC 62028
try {
using(RegistryKey key = Registry.ClassesRoot.OpenSubKey(subkey, false)) {
return ((null != key) ? key.GetValue(queryvalue) : null);
}
}
catch(SecurityException e) {
// Even though we assert permission - it's possible there are
// ACL's on registry that cause SecurityException to be thrown.
ADP.TraceExceptionWithoutRethrow(e);
return null;
}
finally {
RegistryPermission.RevertAssert();
}
}
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
static internal object LocalMachineRegistryValue(string subkey, string queryvalue) { // MDAC 77697
(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\" + subkey)).Assert(); // MDAC 62028
try {
using(RegistryKey key = Registry.LocalMachine.OpenSubKey(subkey, false)) {
return ((null != key) ? key.GetValue(queryvalue) : null);
}
}
catch(SecurityException e) {
// Even though we assert permission - it's possible there are
// ACL's on registry that cause SecurityException to be thrown.
ADP.TraceExceptionWithoutRethrow(e);
return null;
}
finally {
RegistryPermission.RevertAssert();
}
}
// SxS: although this method uses registry, it does not expose anything out
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
static internal void CheckVersionMDAC(bool ifodbcelseoledb) {
// we don't have that version info on the registry implementation, so it won't work.
if (Environment.OSVersion.Platform == PlatformID.Unix)
return;
int major, minor, build;
string version;
try {
version = (string)ADP.LocalMachineRegistryValue("Software\\Microsoft\\DataAccess", "FullInstallVer");
if (ADP.IsEmpty(version)) {
string filename = (string)ADP.ClassesRootRegistryValue(System.Data.OleDb.ODB.DataLinks_CLSID, ADP.StrEmpty);
FileVersionInfo versionInfo = ADP.GetVersionInfo(filename); // MDAC 60411
major = versionInfo.FileMajorPart;
minor = versionInfo.FileMinorPart;
build = versionInfo.FileBuildPart;
version = versionInfo.FileVersion;
}
else {
string[] parts = version.Split('.');
major = Int32.Parse(parts[0], NumberStyles.None, CultureInfo.InvariantCulture);
minor = Int32.Parse(parts[1], NumberStyles.None, CultureInfo.InvariantCulture);
build = Int32.Parse(parts[2], NumberStyles.None, CultureInfo.InvariantCulture);
Int32.Parse(parts[3], NumberStyles.None, CultureInfo.InvariantCulture);
}
}
catch(Exception e) {
//
if (!ADP.IsCatchableExceptionType(e)) {
throw;
}
throw System.Data.OleDb.ODB.MDACNotAvailable(e);
}
// disallow any MDAC version before MDAC 2.6 rtm
// include MDAC 2.51 that ships with Win2k
if ((major < 2) || ((major == 2) && ((minor < 60) || ((minor == 60) && (build < 6526))))) { // MDAC 66628
if (ifodbcelseoledb) {
throw ADP.DataAdapter(Res.GetString(Res.Odbc_MDACWrongVersion, version));
}
else {
throw ADP.DataAdapter(Res.GetString(Res.OleDb_MDACWrongVersion, version));
}
}
}
#endif
// the return value is true if the string was quoted and false if it was not
// this allows the caller to determine if it is an error or not for the quotedString to not be quoted
static internal Boolean RemoveStringQuotes(string quotePrefix, string quoteSuffix, string quotedString, out string unquotedString) {
int prefixLength;
if (quotePrefix == null){
prefixLength = 0;
}
else {
prefixLength = quotePrefix.Length;
}
int suffixLength;
if (quoteSuffix == null){
suffixLength = 0;
}
else{
suffixLength = quoteSuffix.Length;
}
if ((suffixLength + prefixLength) == 0) {
unquotedString = quotedString;
return true;
}
if (quotedString == null){
unquotedString = quotedString;
return false;
}
int quotedStringLength = quotedString.Length;
// is the source string too short to be quoted
if (quotedStringLength < prefixLength + suffixLength){
unquotedString = quotedString;
return false;
}
// is the prefix present?
if ( prefixLength > 0) {
if (quotedString.StartsWith(quotePrefix, StringComparison.Ordinal) == false){
unquotedString = quotedString;
return false;
}
}
// is the suffix present?
if ( suffixLength > 0) {
if (quotedString.EndsWith(quoteSuffix, StringComparison.Ordinal) == false){
unquotedString = quotedString;
return false;
}
unquotedString = quotedString.Substring(prefixLength,quotedStringLength - (prefixLength + suffixLength)).Replace(quoteSuffix+quoteSuffix,quoteSuffix);
}
else {
unquotedString = quotedString.Substring(prefixLength,quotedStringLength - prefixLength);
}
return true;
}
static internal DataRow[] SelectAdapterRows(DataTable dataTable, bool sorted) {
const DataRowState rowStates = DataRowState.Added | DataRowState.Deleted | DataRowState.Modified;
// equivalent to but faster than 'return dataTable.Select("", "", rowStates);'
int countAdded = 0, countDeleted = 0, countModifed = 0;
DataRowCollection rowCollection = dataTable.Rows;
foreach(DataRow dataRow in rowCollection) {
switch(dataRow.RowState) {
case DataRowState.Added:
countAdded++;
break;
case DataRowState.Deleted:
countDeleted++;
break;
case DataRowState.Modified:
countModifed++;
break;
default:
Debug.Assert(0 == (rowStates & dataRow.RowState), "flagged RowState");
break;
}
}
DataRow[] dataRows = new DataRow[countAdded + countDeleted + countModifed];
if(sorted) {
countModifed = countAdded + countDeleted;
countDeleted = countAdded;
countAdded = 0;
foreach(DataRow dataRow in rowCollection) {
switch(dataRow.RowState) {
case DataRowState.Added:
dataRows[countAdded++] = dataRow;
break;
case DataRowState.Deleted:
dataRows[countDeleted++] = dataRow;
break;
case DataRowState.Modified:
dataRows[countModifed++] = dataRow;
break;
default:
Debug.Assert(0 == (rowStates & dataRow.RowState), "flagged RowState");
break;
}
}
}
else {
int index = 0;
foreach(DataRow dataRow in rowCollection) {
if (0 != (dataRow.RowState & rowStates)) {
dataRows[index++] = dataRow;
if (index == dataRows.Length) {
break;
}
}
}
}
return dataRows;
}
internal static int StringLength(string inputString) {
return ((null != inputString) ? inputString.Length : 0);
}
// { "a", "a", "a" } -> { "a", "a1", "a2" }
// { "a", "a", "a1" } -> { "a", "a2", "a1" }
// { "a", "A", "a" } -> { "a", "A1", "a2" }
// { "a", "A", "a1" } -> { "a", "A2", "a1" } // MDAC 66718
static internal void BuildSchemaTableInfoTableNames(string[] columnNameArray) {
Dictionary<string,int> hash = new Dictionary<string,int>(columnNameArray.Length);
int startIndex = columnNameArray.Length; // lowest non-unique index
for (int i = columnNameArray.Length - 1; 0 <= i; --i) {
string columnName = columnNameArray[i];
if ((null != columnName) && (0 < columnName.Length)) {
columnName = columnName.ToLower(CultureInfo.InvariantCulture);
int index;
if (hash.TryGetValue(columnName, out index)) {
startIndex = Math.Min(startIndex, index);
}
hash[columnName] = i;
}
else {
columnNameArray[i] = ADP.StrEmpty; // MDAC 66681
startIndex = i;
}
}
int uniqueIndex = 1;
for (int i = startIndex; i < columnNameArray.Length; ++i) {
string columnName = columnNameArray[i];
if (0 == columnName.Length) { // generate a unique name
columnNameArray[i] = "Column";
uniqueIndex = GenerateUniqueName(hash, ref columnNameArray[i], i, uniqueIndex);
}
else {
columnName = columnName.ToLower(CultureInfo.InvariantCulture);
if (i != hash[columnName]) {
GenerateUniqueName(hash, ref columnNameArray[i], i, 1); // MDAC 66718
}
}
}
}
static private int GenerateUniqueName(Dictionary<string,int> hash, ref string columnName, int index, int uniqueIndex) {
for (;; ++uniqueIndex) {
string uniqueName = columnName + uniqueIndex.ToString(CultureInfo.InvariantCulture);
string lowerName = uniqueName.ToLower(CultureInfo.InvariantCulture); // MDAC 66978
if (!hash.ContainsKey(lowerName)) {
columnName = uniqueName;
hash.Add(lowerName, index);
break;
}
}
return uniqueIndex;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
static internal IntPtr IntPtrOffset(IntPtr pbase, Int32 offset) {
if (4 == ADP.PtrSize) {
return (IntPtr) checked(pbase.ToInt32() + offset);
}
Debug.Assert(8 == ADP.PtrSize, "8 != IntPtr.Size"); // MDAC 73747
return (IntPtr) checked(pbase.ToInt64() + offset);
}
static internal int IntPtrToInt32(IntPtr value) {
if (4 == ADP.PtrSize) {
return (int)value;
}
else {
long lval = (long)value;
lval = Math.Min((long)Int32.MaxValue, lval);
lval = Math.Max((long)Int32.MinValue, lval);
return (int)lval;
}
}
//
static internal int SrcCompare(string strA, string strB) { // this is null safe
return ((strA == strB) ? 0 : 1);
}
static internal int DstCompare(string strA, string strB) { // this is null safe
return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, ADP.compareOptions);
}
static internal bool IsDirection(IDataParameter value, ParameterDirection condition) {
#if DEBUG
IsDirectionValid(condition);
#endif
return (condition == (condition & value.Direction));
}
#if DEBUG
static private void IsDirectionValid(ParameterDirection value) {
switch (value) { // @perfnote: Enum.IsDefined
case ParameterDirection.Input:
case ParameterDirection.Output:
case ParameterDirection.InputOutput:
case ParameterDirection.ReturnValue:
break;
default:
throw ADP.InvalidParameterDirection(value);
}
}
#endif
static internal bool IsEmpty(string str) {
return ((null == str) || (0 == str.Length));
}
static internal bool IsEmptyArray(string[] array) {
return ((null == array) || (0 == array.Length));
}
static internal bool IsNull(object value) {
if ((null == value) || (DBNull.Value == value)) {
return true;
}
INullable nullable = (value as INullable);
return ((null != nullable) && nullable.IsNull);
}
static internal void IsNullOrSqlType(object value, out bool isNull, out bool isSqlType) {
if ((value == null) || (value == DBNull.Value)) {
isNull = true;
isSqlType = false;
}
else {
INullable nullable = (value as INullable);
if (nullable != null) {
isNull = nullable.IsNull;
isSqlType = DataStorage.IsSqlType(value.GetType());
}
else {
isNull = false;
isSqlType = false;
}
}
}
private static Version _systemDataVersion;
static internal Version GetAssemblyVersion() {
// NOTE: Using lazy thread-safety since we don't care if two threads both happen to update the value at the same time
if (_systemDataVersion == null) {
_systemDataVersion = new Version(ThisAssembly.InformationalVersion);
}
return _systemDataVersion;
}
static internal readonly string[] AzureSqlServerEndpoints = {Res.GetString(Res.AZURESQL_GenericEndpoint),
Res.GetString(Res.AZURESQL_GermanEndpoint),
Res.GetString(Res.AZURESQL_UsGovEndpoint),
Res.GetString(Res.AZURESQL_ChinaEndpoint)};
// This method assumes dataSource parameter is in TCP connection string format.
static internal bool IsAzureSqlServerEndpoint(string dataSource)
{
// remove server port
int i = dataSource.LastIndexOf(',');
if (i >= 0)
{
dataSource = dataSource.Substring(0, i);
}
// check for the instance name
i = dataSource.LastIndexOf('\\');
if (i >= 0)
{
dataSource = dataSource.Substring(0, i);
}
// trim redundant whitespaces
dataSource = dataSource.Trim();
// check if servername end with any azure endpoints
for (i = 0; i < AzureSqlServerEndpoints.Length; i++)
{
if (dataSource.EndsWith(AzureSqlServerEndpoints[i], StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
}
}
|