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