Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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)));
        }
Esempio n. 4
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]);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
    }
Esempio n. 7
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);
            }
        }