static private void ValidateProvider(string progid) {
     if (ADP.IsEmpty(progid)) {
         throw ODB.NoProviderSpecified();
     }
     if (ODB.MaxProgIdLength <= progid.Length) { // MDAC 63151
         throw ODB.InvalidProviderSpecified();
     }
     progid = progid.ToLower(CultureInfo.InvariantCulture);
     if (IsMSDASQL(progid)) {
         // fail msdasql even if not on the machine.
         throw ODB.MSDASQLNotSupported();
     }
 }
Esempio n. 2
0
 private static void ValidateProvider(string progid)
 {
     if (ADP.IsEmpty(progid))
     {
         throw ODB.NoProviderSpecified();
     }
     if (0xff <= progid.Length)
     {
         throw ODB.InvalidProviderSpecified();
     }
     progid = progid.ToLower(CultureInfo.InvariantCulture);
     if (IsMSDASQL(progid))
     {
         throw ODB.MSDASQLNotSupported();
     }
 }
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;
        }