OdbcConnectionString.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //------------------------------------------------------------------------------
  2. // <copyright file="OdbcConnectionString.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. namespace System.Data.Odbc {
  9. using System;
  10. using System.Collections;
  11. using System.Data;
  12. using System.Data.Common;
  13. using System.Security;
  14. using System.Security.Permissions;
  15. using System.Text;
  16. internal sealed class OdbcConnectionString : DbConnectionOptions {
  17. // instances of this class are intended to be immutable, i.e readonly
  18. // used by pooling classes so it is much easier to verify correctness
  19. // when not worried about the class being modified during execution
  20. private static class KEY {
  21. internal const string SaveFile = "savefile";
  22. }
  23. private readonly string _expandedConnectionString;
  24. internal OdbcConnectionString(string connectionString, bool validate) : base(connectionString, null, true) {
  25. if (!validate) {
  26. string filename = null;
  27. int position = 0;
  28. _expandedConnectionString = ExpandDataDirectories(ref filename, ref position);
  29. }
  30. if (validate || (null == _expandedConnectionString)) {
  31. // do not check string length if it was expanded because the final result may be shorter than the original
  32. if ((null != connectionString) && (ODBC32.MAX_CONNECTION_STRING_LENGTH < connectionString.Length)) { // MDAC 83536
  33. throw ODBC.ConnectionStringTooLong();
  34. }
  35. }
  36. }
  37. protected internal override System.Security.PermissionSet CreatePermissionSet() {
  38. System.Security.PermissionSet permissionSet;
  39. if (ContainsKey(KEY.SaveFile)) {
  40. permissionSet = new NamedPermissionSet("FullTrust");
  41. }
  42. else {
  43. permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
  44. permissionSet.AddPermission(new OdbcPermission(this));
  45. }
  46. return permissionSet;
  47. }
  48. protected internal override string Expand() {
  49. if (null != _expandedConnectionString) {
  50. return _expandedConnectionString;
  51. }
  52. else {
  53. return base.Expand();
  54. }
  55. }
  56. }
  57. }