Esempio n. 1
0
        private string ValidateConnectionString(string connectionString)
        {
            if (base.ConvertValueToBoolean("asynchronous processing", false))
            {
                throw ODB.AsynchronousNotSupported();
            }
            if (base.ConvertValueToInt32("connect timeout", 0) < 0)
            {
                throw ADP.InvalidConnectTimeoutValue();
            }
            string progid = base.ConvertValueToString("data provider", null);

            if (progid != null)
            {
                progid = progid.Trim();
                if (0 < progid.Length)
                {
                    ValidateProvider(progid);
                }
            }
            progid = base.ConvertValueToString("remote provider", null);
            if (progid != null)
            {
                progid = progid.Trim();
                if (0 < progid.Length)
                {
                    ValidateProvider(progid);
                }
            }
            progid = base.ConvertValueToString("provider", ADP.StrEmpty).Trim();
            ValidateProvider(progid);
            this._oledbServices = -13;
            if (!base.ContainsKey("ole db services") || ADP.IsEmpty(base["ole db services"]))
            {
                string g = (string)ADP.ClassesRootRegistryValue(progid + @"\CLSID", string.Empty);
                if ((g != null) && (0 < g.Length))
                {
                    Guid guid = new Guid(g);
                    if (ODB.CLSID_MSDASQL == guid)
                    {
                        throw ODB.MSDASQLNotSupported();
                    }
                    object obj2 = ADP.ClassesRootRegistryValue(@"CLSID\{" + guid.ToString("D", CultureInfo.InvariantCulture) + "}", "OLEDB_SERVICES");
                    if (obj2 == null)
                    {
                        return(connectionString);
                    }
                    try
                    {
                        this._oledbServices = (int)obj2;
                    }
                    catch (InvalidCastException exception)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception);
                    }
                    this._oledbServices &= -13;
                    StringBuilder builder = new StringBuilder();
                    builder.Append("ole db services");
                    builder.Append("=");
                    builder.Append(this._oledbServices.ToString(CultureInfo.InvariantCulture));
                    builder.Append(";");
                    builder.Append(connectionString);
                    connectionString = builder.ToString();
                }
                return(connectionString);
            }
            this._oledbServices = base.ConvertValueToInt32("ole db services", -13);
            return(connectionString);
        }
Esempio n. 2
0
        private string ValidateConnectionString(string connectionString)
        {
            if (ConvertValueToBoolean(KEY.Asynchronous_Processing, false))
            {
                throw ODB.AsynchronousNotSupported();
            }

            int connectTimeout = ConvertValueToInt32(KEY.Connect_Timeout, 0);

            if (connectTimeout < 0)
            {
                throw ADP.InvalidConnectTimeoutValue();
            }

            string progid = ConvertValueToString(KEY.Data_Provider, null); // MDAC 71923

            if (null != progid)
            {
                progid = progid.Trim();
                if (0 < progid.Length)   // don't fail on empty 'Data Provider' value
                {
                    ValidateProvider(progid);
                }
            }
            progid = ConvertValueToString(KEY.RemoteProvider, null); // MDAC 71923
            if (null != progid)
            {
                progid = progid.Trim();
                if (0 < progid.Length)   // don't fail on empty 'Data Provider' value
                {
                    ValidateProvider(progid);
                }
            }
            progid = ConvertValueToString(KEY.Provider, ADP.StrEmpty).Trim();
            ValidateProvider(progid); // will fail on empty 'Provider' value

            // SQLBU VSTS 59322: initialize to default
            // If the value is not provided in connection string and OleDbServices registry key has not been set by the provider,
            // the default for the provider is -1 (all services are ON).
            // our default is -13, we turn off ODB.DBPROPVAL_OS_AGR_AFTERSESSION and ODB.DBPROPVAL_OS_CLIENTCURSOR flags
            _oledbServices = DbConnectionStringDefaults.OleDbServices;

            bool hasOleDBServices = (base.ContainsKey(KEY.Ole_DB_Services) && !ADP.IsEmpty((string)base[KEY.Ole_DB_Services]));

            if (!hasOleDBServices)   // don't touch registry if they have OLE DB Services
            {
                string classid = (string)ADP.ClassesRootRegistryValue(progid + "\\CLSID", String.Empty);
                if ((null != classid) && (0 < classid.Length))
                {
                    // CLSID detection of 'Microsoft OLE DB Provider for ODBC Drivers'
                    Guid classidProvider = new Guid(classid);
                    if (ODB.CLSID_MSDASQL == classidProvider)
                    {
                        throw ODB.MSDASQLNotSupported();
                    }
                    object tmp = ADP.ClassesRootRegistryValue("CLSID\\{" + classidProvider.ToString("D", CultureInfo.InvariantCulture) + "}", ODB.OLEDB_SERVICES);
                    if (null != tmp)
                    {
                        // @devnote: some providers like MSDataShape don't have the OLEDB_SERVICES value
                        // the MSDataShape provider doesn't support the 'Ole Db Services' keyword
                        // hence, if the value doesn't exist - don't prepend to string
                        try {
                            _oledbServices = (int)tmp;
                        }
                        catch (InvalidCastException e) {
                            ADP.TraceExceptionWithoutRethrow(e);
                        }
                        _oledbServices &= ~(ODB.DBPROPVAL_OS_AGR_AFTERSESSION | ODB.DBPROPVAL_OS_CLIENTCURSOR); // NT 347436, MDAC 58606

                        StringBuilder builder = new StringBuilder();
                        builder.Append(KEY.Ole_DB_Services);
                        builder.Append("=");
                        builder.Append(_oledbServices.ToString(CultureInfo.InvariantCulture));
                        builder.Append(";");
                        builder.Append(connectionString);
                        connectionString = builder.ToString();
                    }
                }
            }
            else
            {
                // SQLBU VSTS 59322: parse the Ole Db Services value from connection string
                _oledbServices = ConvertValueToInt32(KEY.Ole_DB_Services, DbConnectionStringDefaults.OleDbServices);
            }

            return(connectionString);
        }
Esempio n. 3
0
        override protected string ValidateParse() {
            int connectTimeout = base.CheckConvertToInt32(KEY.Connect_Timeout, 0);
            if (connectTimeout < 0) {
                throw ADP.InvalidConnectTimeoutValue();
            }

            if (!CheckConvertToBoolean(KEY.Persist_Security_Info, false)) {
                // because we allow the user direct access to the ole db properties and
                // we've changed the default of 'persisit security info' from true to false
                // we need to force the provider to hide the password
                //if (!base.Contains(KEY.Ole_DB_Services) || (null == (value = base[KEY.Ole_DB_Services]))) {
                //    hiddenConnectionString += ";persist security info=false;";
                //}
            }

            if (CheckConvertToBoolean(KEY.Asynchronous_Processing, false)) {
                throw ODB.AsynchronousNotSupported();
            }

            bool hasOleDBServices = (base.Contains(KEY.Ole_DB_Services) && !ADP.IsEmpty((string)base[KEY.Ole_DB_Services]));

            string progid = CheckConvertToString(KEY.Data_Provider, null); // MDAC 71923
            if (null != progid) {
                ValidateNotMSDASQL(progid);
            }
            
            progid = CheckConvertToString(KEY.Provider, null);
            if (null != progid) {
                progid = progid.Trim();
            }
            if (ADP.IsEmpty(progid)) {
                throw ODB.NoProviderSpecified();
            }
            if (ODB.MaxProgIdLength <= progid.Length) { // MDAC 63151
                throw ODB.InvalidProviderSpecified();
            }
            ValidateNotMSDASQL(progid);

            if (!hasOleDBServices) { // don't touch registry if they have OLE DB Services
                string classid = (string) ADP.ClassesRootRegistryValue(progid + "\\CLSID", String.Empty);
                if ((null != classid) && (0 < classid.Length)) {
                    // CLSID detection of 'Microsoft OLE DB Provider for ODBC Drivers'
                    if (ODB.CLSID_MSDASQL == new Guid(classid)) {
                        throw ODB.MSDASQLNotSupported();
                    }
                    object tmp = ADP.ClassesRootRegistryValue("CLSID\\" + classid, ODB.OLEDB_SERVICES);
                    if (null != tmp) {
                        Int32 oledbservices = 0;

                        // @devnote: some providers like MSDataShape don't have the OLEDB_SERVICES value
                        // the MSDataShape provider doesn't support the 'Ole Db Services' keyword
                        // hence, if the value doesn't exist - don't prepend to string
                        try {
                            oledbservices  = Convert.ToInt32(tmp);
                        }
                        catch(Exception e) {
                            ADP.TraceException(e);
                        }
                        oledbservices &= ~(ODB.DBPROPVAL_OS_AGR_AFTERSESSION | ODB.DBPROPVAL_OS_CLIENTCURSOR); // NT 347436, MDAC 58606
                        _oledbservices = oledbservices;

                        // prepend 'OLE DB SERVICES=-13' (or with registry bits included)
#if USECRYPTO
                        byte[] newconstr;
                        string prepend = ODB.Ole_DB_Services + "=" + oledbservices.ToString(System.Globalization.CultureInfo.InvariantCulture) + ";";
                        byte[] plainText = Crypto.DecryptString(EncryptedActualConnectionString);
                        GCHandle handle = GCHandle.Alloc(plainText, GCHandleType.Pinned);
                        try {
                            newconstr = new byte[ADP.CharSize*prepend.Length + plainText.Length];
                            GCHandle newhandle = GCHandle.Alloc(newconstr, GCHandleType.Pinned);
                            try {
                                System.Text.Encoding.Unicode.GetBytes(prepend, 0, prepend.Length, newconstr, 0);
                                plainText.CopyTo(newconstr, ADP.CharSize*prepend.Length);
                                newconstr = Crypto.EncryptOrDecryptData(true, newconstr, 0, newconstr.Length);
                            }
                            catch {
                                Array.Clear(newconstr, 0, newconstr.Length);
                                if (newhandle.IsAllocated) {
                                    newhandle.Free();
                                }
                                throw;
                            }
                            if (newhandle.IsAllocated) {
                                newhandle.Free();
                            }
                        }
                        finally {
                            Array.Clear(plainText, 0, plainText.Length);
                            if (handle.IsAllocated) {
                                handle.Free();
                            }
                        }
                        return System.Text.Encoding.Unicode.GetString(newconstr, 0, newconstr.Length);
#else
                        StringBuilder builder = new StringBuilder();
                        builder.Append(ODB.Ole_DB_Services);
                        builder.Append("=");
                        builder.Append(oledbservices.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        builder.Append(";");
                        builder.Append(EncryptedActualConnectionString);
                        return builder.ToString();
#endif
                    }
                }
            }
            else {
                _oledbservices = CheckConvertToInt32(KEY.Ole_DB_Services, 0);
            }
            return EncryptedActualConnectionString;
        }