Exemplo n.º 1
0
        public static void FindProvider()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();

            var list = new List <String>();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        list.Add(reader.GetValue(i).ToString());
                    }
                }
            }
            reader.Close();
            foreach (var provider in list)
            {
                if (provider.StartsWith("Microsoft.ACE.OLEDB"))
                {
                    Console.WriteLine(provider.ToString());
                    //this.provider = provider.ToString();
                }
            }
        }
Exemplo n.º 2
0
        private bool MakeConnString()
        {
            bool retVar = true;
            //поиск провайдера построен по тому же принципу как и поиск таблицы в базе
            string          flExt      = Path.GetExtension(dbName);
            OleDbEnumerator enumerator = new OleDbEnumerator();
            bool            isNewOle   = (enumerator.GetElements().Select("SOURCES_DESCRIPTION LIKE 'Microsoft.ACE.OLEDB%'").Length > 0) || (enumerator.GetElements().Select("SOURCES_DESCRIPTION LIKE '%Access Database Engine OLE DB%'").Length > 0); // new OleDB provider
            bool            isOldOle   = enumerator.GetElements().Select("SOURCES_DESCRIPTION = 'Microsoft Jet 4.0 OLE DB Provider'").Length > 0;                                                                                                       // old OleDB provider

            if (isNewOle)                                                                                                                                                                                                                               // новая версия
            {
                dbConStr += (dbName + "; Persist Security Info=False ");                                                                                                                                                                                //"; Persist Security Info=False;");
            }
            else
            {
                if (flExt == ".mdb" && isOldOle)
                {
                    dbConStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + dbName + "; Persist Security Info=False;User ID=Admin;Password=";
                }
                else
                {
                    retVar = false;
                }
            }
            return(retVar);
        }
Exemplo n.º 3
0
        // Get a provider with filter string in name
        public static string GetProvider(string filter)
        {
            OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();
            int             sel    = 0;

            for (int i = 0; i < reader.FieldCount; i++)
            {
                if (reader.GetName(i) == "SOURCES_NAME")
                {
                    sel = i;
                    break;
                }
            }

            Console.WriteLine("Searching Providers ...");
            while (reader.Read())
            {
                Console.WriteLine("\t ...{0}", reader.GetValue(sel));
                if (reader.GetValue(sel).ToString().Contains(filter))
                {
                    Console.WriteLine("Provider: {0}", reader.GetValue(sel));
                    return(reader.GetValue(sel).ToString());
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        private List <string> StartNetworkScan(CancellationToken ct)
        {
            List <string> localNetworks = new List <string>();

            if (ct.IsCancellationRequested)
            {
                return(localNetworks);
            }

            using (OleDbDataReader reader = OleDbEnumerator.GetEnumerator(Type.GetTypeFromProgID("SQLOLEDB Enumerator"))) {
                while (reader.Read())
                {
                    if (ct.IsCancellationRequested)
                    {
                        return(localNetworks);
                    }
                    object[] row = new object[reader.FieldCount];
                    reader.GetValues(row);
                    string networkHost = (string)row[0];

                    if (!localNetworks.Contains(networkHost))
                    {
                        localNetworks.Add(networkHost);
                    }
                }
            }

            return(localNetworks);
        }
Exemplo n.º 5
0
        private static bool IsAccessDriver64Installed()
        {
            try
            {
                OleDbEnumerator enumerator  = new OleDbEnumerator();
                DataTable       table       = enumerator.GetElements();
                bool            bNameFound  = false;
                bool            bCLSIDFound = false;

                foreach (DataRow row in table.Rows)
                {
                    foreach (DataColumn col in table.Columns)
                    {
                        if ((col.ColumnName.Contains("SOURCES_NAME")) && (row[col].ToString().Contains(_aceOledbProviderName)))
                        {
                            bNameFound = true;
                        }
                        if ((col.ColumnName.Contains("SOURCES_CLSID")) && (row[col].ToString().Contains(_aceOledbClsId)))
                        {
                            bCLSIDFound = true;
                        }
                    }
                }
                return(bNameFound && bCLSIDFound);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Gets the connection string based on the provider that has been installed.
        /// </summary>
        /// <param name="excelFileName">Name of the excel file.</param>
        /// <returns>Returns a <see cref="string" /> representing the connection string.</returns>
        private static string GetConnectionString(string excelFileName)
        {
            OleDbEnumerator enumerator = new OleDbEnumerator();
            DataTable       table      = enumerator.GetElements();

            bool name  = false;
            bool clsid = false;

            foreach (DataRow row in table.Rows)
            {
                foreach (DataColumn col in table.Columns)
                {
                    if ((col.ColumnName.Contains("SOURCES_NAME")) && (row[col].ToString().Contains("Microsoft.ACE.OLEDB.12.0")))
                    {
                        name = true;
                    }
                    if ((col.ColumnName.Contains("SOURCES_CLSID")) && (row[col].ToString().Contains("{3BE786A0-0366-4F5C-9434-25CF162E475E}")))
                    {
                        clsid = true;
                    }
                }
            }

            if (name && clsid)
            {
                return(string.Format(CultureInfo.InvariantCulture, "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES\";", excelFileName));
            }

            return(string.Format(CultureInfo.InvariantCulture, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Text"";", Path.GetDirectoryName(excelFileName)));
        }
Exemplo n.º 7
0
        private void FillDataSources()
        {
            DataTable table = new DataTable();

            table.Locale = CultureInfo.InvariantCulture;
            try
            {
                OleDbDataReader enumerator = OleDbEnumerator.GetEnumerator(
                    Type.GetTypeFromCLSID(new Guid("C8B522CD-5CF3-11ce-ADE5-00AA0044773D")));
                using (enumerator)
                {
                    table.Load(enumerator);
                }
            }
            catch
            {
            }

            cbxDsName.Items.Clear();
            foreach (DataRow row in table.Rows)
            {
                cbxDsName.Items.Add(row["SOURCES_NAME"].ToString());
            }
            cbxDsName.Sorted = true;
        }
        /// <summary>
        /// Gets all available OLE DB providers installed on the
        /// current machine. Note this list will vary when running
        /// under 32-bit versions of the OS versus 64-bit versions.
        /// </summary>
        /// <returns></returns>
        public static Task <IEnumerable <IOleDbProvider> > GetOleDbProvidersAsync()
        {
            IList <IOleDbProvider> returnValue = null;

            using (OleDbDataReader rdr = OleDbEnumerator.GetRootEnumerator())
            {
                returnValue = new List <IOleDbProvider>();

                while (rdr.Read())
                {
                    OleDbProvider item = new OleDbProvider
                    {
                        Name        = rdr.GetString(0),
                        Key         = rdr.GetString(1),
                        Description = rdr.GetString(2),
                        Type        = rdr.GetInt32(3),
                        IsParent    = rdr.GetBoolean(4),
                        ClsId       = Guid.Parse(rdr.GetString(5))
                    };

                    returnValue.Add(item);
                }
                ;
            }

            return(Task.FromResult((IEnumerable <IOleDbProvider>)returnValue));
        }
        static void Main(string[] args)
        {
            OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();

            DisplayData(reader);

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 10
0
        private static void DumpProviders()
        {
            var lister = OleDbEnumerator.GetRootEnumerator();

            Console.WriteLine("OleDb enumeration:");
            while (lister.NextResult())
            {
                Console.WriteLine("name: {0} description: {1}", lister[0], lister[2]);
            }
        }
Exemplo n.º 11
0
        private void LoadOleDB()
        {
            // OleDbEnumerator enumerator = new OleDbEnumerator();
            OleDbEnumerator enumerator = new OleDbEnumerator();
            DataTable       d          = enumerator.GetElements();

            foreach (DataRow dc in d.Rows)
            {
                listBox1.Items.Add(dc[2]);
            }
        }
Exemplo n.º 12
0
        public static void Information()
        {
            DataTable table = new OleDbEnumerator().GetElements();
            string    inf   = "";

            foreach (DataRow row in table.Rows)
            {
                inf += row["SOURCES_NAME"] + "\n";
            }

            MessageBox.Show(inf);
        }
        /// <summary>
        /// Gets the registered OLE DB providers as an array of ProgIDs.
        /// </summary>
        public static List <string> GetRegisteredProviders()
        {
            // Get the sources rowset for the root OLE DB enumerator
            Type            rootEnumeratorType = Type.GetTypeFromCLSID(NativeMethods.CLSID_OLEDB_ENUMERATOR);
            OleDbDataReader dr = OleDbEnumerator.GetEnumerator(rootEnumeratorType);

            // Read the CLSIDs of each data source (not binders or enumerators)
            Dictionary <string, string> sources = new Dictionary <string, string>();           // avoids duplicate entries

            using (dr)
            {
                while (dr.Read())
                {
                    int type = (int)dr["SOURCES_TYPE"];
                    if (type == NativeMethods.DBSOURCETYPE_DATASOURCE_TDP ||
                        type == NativeMethods.DBSOURCETYPE_DATASOURCE_MDP)
                    {
                        sources[dr["SOURCES_CLSID"] as string] = null;
                    }
                }
            }             // reader is disposed here

            // Get the ProgID for each data source
            List <string> sourceProgIds = new List <string>(sources.Count);

            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID");
            using (key)
            {
                foreach (KeyValuePair <string, string> source in sources)
                {
                    Microsoft.Win32.RegistryKey subKey = key.OpenSubKey(source.Key + "\\ProgID");
                    // if this subkey does not exist, ignore it.
                    if (subKey != null)
                    {
                        using (subKey)
                        {
                            sourceProgIds.Add(subKey.GetValue(null) as string);
                        }                         // subKey is disposed here
                    }
                }
            }             // key is disposed here

            // Sort the prog ID array by name
            sourceProgIds.Sort();

            // The OLE DB provider for ODBC is not supported by the OLE DB .NET provider, so remove it
            while (sourceProgIds.Contains("MSDASQL.1"))
            {
                sourceProgIds.Remove("MSDASQL.1");
            }

            return(sourceProgIds);
        }
 private static string GetMsAccessProvider(string providerBase)
 {
     using (OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator())
     {
         while (reader.Read())
         {
             string providerName = reader.GetString(reader.GetOrdinal("SOURCES_NAME")).Trim();
             if (providerName.StartsWith(providerBase, StringComparison.OrdinalIgnoreCase))
             {
                 return(providerName);
             }
         }
     }
     return(string.Empty);
 }
Exemplo n.º 15
0
        public static void Main()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    Console.WriteLine("{0} = {1}", reader.GetName(i), reader.GetValue(i));
                }

                Console.WriteLine();
            }
            reader.Close();
        }
Exemplo n.º 16
0
        public static string GetOleDBProviders()
        {
            OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();
            DataTable       dt     = new DataTable();

            dt.Load(reader);
            string list = null;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                list += $"{dt.Rows[i]["SOURCES_NAME"].ToString()};";
            }
            string[] mlist = list.Split(';');
            GetOleDbProvidersCompleted?.Invoke(null, mlist);
            return(list);
        }
        private static List <string> GetProvidersList()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();
            var result = new List <string>();

            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        result.Add(reader.GetValue(i).ToString());
                    }
                }
            }
            reader.Close();

            return(result);
        }
Exemplo n.º 18
0
        static void DisplayData()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();

            var list = new List <String>();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        list.Add(reader.GetValue(i).ToString());
                    }
                }
                Console.WriteLine("{0} = {1}", reader.GetName(0), reader.GetValue(0));
            }
            reader.Close();
        }
Exemplo n.º 19
0
        private void PopulateProvidersComboBox()
        {
            providers = new Dictionary <string, string>();
            OleDbDataReader rootEnumerator = OleDbEnumerator.GetRootEnumerator();

            if (rootEnumerator != null)
            {
                foreach (DbDataRecord dbDataRecord in rootEnumerator)
                {
                    string text = dbDataRecord[2] as string;
                    providers[text] = (dbDataRecord[0] as string);
                    int num = (int)dbDataRecord[3];
                    if ((!cmbProvider.Items.Contains(text) && 1 == num) || 3 == num)
                    {
                        cmbProvider.Items.Add(text);
                    }
                }
            }
        }
Exemplo n.º 20
0
        private void DisplayData()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();

            var list = new List <String>();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        list.Add(reader.GetValue(i).ToString());
                    }
                }
                listBox1.Items.Add(reader.GetName(0) + " - " + reader.GetValue(0));
            }
            reader.Close();
        }
Exemplo n.º 21
0
        // list all OLEDB Providers to CLI
        public static void ShowProviders()
        {
            OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();

            //OleDbDataReader reader = enumerator.GetElements();
            for (int i = 0; i < reader.FieldCount; i++)
            {
                Console.Write("{0}\t", reader.GetName(i));
            }
            Console.WriteLine("");
            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    Console.Write("{0}\t", reader.GetValue(i));
                }
                Console.WriteLine("");
            }
        }
Exemplo n.º 22
0
        private static string GetProvider()
        {
            var reader   = OleDbEnumerator.GetRootEnumerator();
            var provider = string.Empty;

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME" && reader.GetValue(0).ToString().Contains("Microsoft.ACE.OLEDB"))
                    {
                        provider = reader.GetValue(i).ToString();
                        break;
                    }
                }
            }

            reader.Close();
            return(provider);
        }
Exemplo n.º 23
0
    protected void DisplayData()
    {
        var   reader = OleDbEnumerator.GetRootEnumerator();
        Label dbinfo = (Label)Panel1.FindControl("dbinfo");

        var list = new List <String>();

        while (reader.Read())
        {
            for (var i = 0; i < reader.FieldCount; i++)
            {
                if (reader.GetName(i) == "SOURCES_NAME")
                {
                    list.Add(reader.GetValue(i).ToString());
                }
            }

            dbinfo.Text += reader.GetName(0) + "=" + reader.GetValue(0) + "<br/>";
            //Console.WriteLine("{0} = {1}", reader.GetName(0), reader.GetValue(0));
        }
        reader.Close();
    }
Exemplo n.º 24
0
    static void Main()
    {
        var oleEnum = new OleDbEnumerator();
        var elems   = oleEnum.GetElements();

/*
 *      https://stackoverflow.com/questions/37849262/how-to-get-a-list-of-installed-ole-db-providers#61328613
 */
        if (elems != null && elems.Rows != null)
        {
            foreach (System.Data.DataRow row in elems.Rows)
            {
                if (!row.IsNull("SOURCES_NAME") && row["SOURCES_NAME"] is string)
                {
                    Console.WriteLine(row["SOURCES_NAME"]);
                }
            }
        }

        Console.WriteLine("##################################");
        DisplayData(elems);
    }
Exemplo n.º 25
0
        /// <summary>
        /// Check whether the machine has the MSOLAP driver installed
        /// The driver could be available in 32-bit and not in 64-bit
        /// This would work in Excel, but it is better to try get the driver in that case
        /// </summary>
        /// <returns></returns>
        public static bool HasMsOlapDriver()
        {
            const string SOURCES_NAME = "SOURCES_NAME";

            var oleEnum = new OleDbEnumerator();
            var elems   = oleEnum.GetElements();

            if (elems != null && elems.Rows != null)
            {
                foreach (System.Data.DataRow row in elems.Rows)
                {
                    if (!row.IsNull(SOURCES_NAME) && row[SOURCES_NAME] is string)
                    {
                        if (row[SOURCES_NAME].ToString() == MSOLAP_DRIVER_NAME)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            OleDbEnumerator e  = new OleDbEnumerator();
            DataTable       dt = e.GetElements();

            List <string> strings = new List <string>
            {
                "Provider=sqloledb;Data Source=NSIGPB_AGL;Initial Catalog=GPBNSI_CURRENT;Integrated Security=SSPI;",
                "Provider=MSDAORA.1;Data Source=ORACLERDF64;Persist Security Info=True;User ID=NORMA_CB_NEW;Password=NORMA_CB_NEW;",
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"\\\\w4dev3\\c$\\te mp\\Feoktistov\\DKSNSI-8777\\Родитель_КР1-Пакет_0-15.01.2019-16_42.xls\";Extended Properties=\"Excel 8.0; HDR = Yes; IMEX = 1\"",
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"\\\\w4dev3\\1.mdb\";User ID=;Password=;",
                "Provider=PGNP.1;Password=sasha2;Persist Security Info=True;User ID=sasha;Initial Catalog=dbname;Data Source=srv;Extended Properties=\"PORT=5432; SSL = allow; \"",
                "Provider=MySqlProv.3.9;Data Source=sui;Password=syu;User ID=sty;Location=srt;Extended Properties=\"PORT=3306; \"",
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"\\\\w4dev3\\c$\";Extended Properties=\"text; HDR = Yes; FMT = Delimited; CharacterSet = 65001; \"",
                "Provider=VFPOLEDB.1;Data Source=\"\\\\w4dev3\\c$\";",
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"\\\\w4dev3\\c$\";Extended Properties=dBASE IV;User ID=;Password="
            };

            foreach (string s in strings)
            {
                OleDbConnectionStringBuilder b = new OleDbConnectionStringBuilder(s);
            }
        }
Exemplo n.º 27
0
        public static bool IsOleDbDriverInstalled(OledDbDriverName oleDbDriverName)
        {
            string driverName = GetDriverName(oleDbDriverName);
            var    reader     = OleDbEnumerator.GetRootEnumerator();
            var    list       = new List <String>();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        if (reader.GetValue(i).ToString() == driverName)
                        {
                            reader.Close();
                            return(true);
                        }
                    }
                }
            }
            reader.Close();
            return(false);
        }
Exemplo n.º 28
0
        static public bool oledbExistTest()
        {
            var reader = OleDbEnumerator.GetRootEnumerator();

            var list = new List <String>();

            while (reader.Read())
            {
                for (var i = 0; i < reader.FieldCount; i++)
                {
                    if (reader.GetName(i) == "SOURCES_NAME")
                    {
                        list.Add(reader.GetValue(i).ToString());
                        if (reader.GetValue(i).ToString() == "Microsoft.ACE.OLEDB.12.0")
                        {
                            return(true);
                        }
                    }
                }
                //Console.WriteLine("{0} = {1}", reader.GetName(0), reader.GetValue(0));
            }
            reader.Close();
            return(false);
        }
        private void EnumerateProviders()
        {
            OleDbDataReader dr = null;

            try
            {
                // Get the sources rowset for the root OLE DB enumerator
                dr = OleDbEnumerator.GetEnumerator(Type.GetTypeFromCLSID(NativeMethods.CLSID_OLEDB_ENUMERATOR));

                // Get the CLSIDs and descriptions of each data source (not binders or enumerators)
                Dictionary <string, string> sources = new Dictionary <string, string>();               // avoids duplicate entries
                while (dr.Read())
                {
                    int type = dr.GetInt32(dr.GetOrdinal("SOURCES_TYPE"));
                    if (type == NativeMethods.DBSOURCETYPE_DATASOURCE_TDP ||
                        type == NativeMethods.DBSOURCETYPE_DATASOURCE_MDP)
                    {
                        string clsId       = dr["SOURCES_CLSID"].ToString();
                        string description = dr["SOURCES_DESCRIPTION"].ToString();
                        sources[clsId] = description;
                    }
                }

                // Get the full ProgID for each data source
                Dictionary <string, string> sourceProgIds = new Dictionary <string, string>(sources.Count);
                _providers = new List <ProviderType>();
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID");
                using (key)
                {
                    foreach (KeyValuePair <string, string> source in sources)
                    {
                        Microsoft.Win32.RegistryKey subKey = key.OpenSubKey(source.Key + "\\ProgID");
                        if (subKey != null)
                        {
                            using (subKey)
                            {
                                string progId = key.OpenSubKey(source.Key + "\\ProgID").GetValue(null) as string;
                                if (progId != null &&
                                    !progId.Equals("MSDASQL", StringComparison.OrdinalIgnoreCase) &&
                                    !progId.StartsWith("MSDASQL.", StringComparison.OrdinalIgnoreCase) &&
                                    !progId.Equals("Microsoft OLE DB Provider for ODBC Drivers"))
                                {
                                    sourceProgIds[progId] = source.Key;
                                }
                            }                             // subKey is disposed here
                        }
                    }
                }                 // key is disposed here
                                  // Populate the combo box
                foreach (KeyValuePair <string, string> entry in sourceProgIds)
                {
                    _providers.Add(new ProviderType()
                    {
                        Name = entry.Key, DisplayName = sources[entry.Value]
                    });
                }
                _providers = _providers.OrderBy(x => x.DisplayName).ToList <ProviderType>();
            }
            finally
            {
                if (dr != null)
                {
                    dr.Dispose();
                }
            }
        }
Exemplo n.º 30
0
 public void GetEnumerator_BadType_Throws()
 {
     Assert.Throws <ArgumentException>(() => OleDbEnumerator.GetEnumerator(typeof(Exception)));
 }