/// <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));
        }
        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();
                }
            }
        }
Exemple #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);
        }
        static void Main(string[] args)
        {
            OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();

            DisplayData(reader);

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemple #5
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]);
            }
        }
 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);
 }
Exemple #7
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();
        }
Exemple #8
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);
        }
Exemple #9
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("");
            }
        }
Exemple #10
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);
                    }
                }
            }
        }
Exemple #11
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();
        }
Exemple #12
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();
        }
        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);
        }
Exemple #14
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);
        }
Exemple #15
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();
    }
Exemple #16
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);
        }
Exemple #17
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);
        }