Exemplo n.º 1
0
        /// <summary>
        /// Method that returns driver object based on the driver name.
        /// </summary>
        /// <param name="driverName"></param>
        /// <returns>ODBCDriver object</returns>
        public static OdbcDriver GetODBCDriver(string driverName)
        {
            OdbcDriver odbcDriver = null;

            // Get the key for ODBCINST_INI_LOC_IN_REGISTRY+dsnName.
            using (RegistryKey driverNameKey = GetLocalMachineKey().OpenSubKey(ODBCINST_INI_LOC_IN_REGISTRY + driverName, false))
            {
                if (driverNameKey != null)
                {
                    // Get all elements defined in the above key
                    string[] driverElements = driverNameKey.GetValueNames();

                    var data = new Dictionary <string, string>(driverElements.Length);

                    // For each element defined for a typical Driver get
                    // its value.
                    foreach (string driverElement in driverElements)
                    {
                        data.Add(driverElement, driverNameKey.GetValue(driverElement).ToString());
                    }

                    // Create ODBCDriver Object.
                    odbcDriver = OdbcDriver.ParseForDriver(driverName, data);
                }
                return(odbcDriver);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that gives the ODBC Drivers installed in the local machine.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <OdbcDriver> GetODBCDrivers()
        {
            List <OdbcDriver> result = new List <OdbcDriver>();
            var driverNames          = GetODBCDriverNames();

            if (driverNames != null)
            {
                // Foreach Driver entry in the ODBC_DRIVERS_LOC_IN_REGISTRY,
                // goto the Key ODBCINST_INI_LOC_IN_REGISTRY+driver and get
                // elements of the DSN entry to create ODBCDSN objects.
                foreach (string driverName in driverNames)
                {
                    OdbcDriver odbcDriver = GetODBCDriver(driverName);
                    if (odbcDriver != null)
                    {
                        result.Add(odbcDriver);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public static OdbcDriver ParseForDriver(string driverName, Dictionary <string, string> data)
        {
            OdbcDriver odbcdriver = new OdbcDriver()
            {
                ODBCDriverName = driverName
            };


            // For each element defined for a typical Driver get
            // its value.
            foreach (var driverElement in data)
            {
                string v = driverElement.Value;
                switch (driverElement.Key.ToLower())
                {
                case "apilevel":
                    odbcdriver.APILevel = v;
                    break;

                case "connectfunctions":
                    odbcdriver.ConnectFunctions = v;
                    break;

                case "driver":
                    odbcdriver.DriverDLL = v;
                    break;

                case "driverodbcver":
                    odbcdriver.DriverODBCVer = v;
                    break;

                case "fileextns":
                    odbcdriver.FileExtns = v;
                    break;

                case "fileusage":
                    odbcdriver.FileUsage = v;
                    break;

                case "setup":
                    odbcdriver.SetUp = v;
                    break;

                case "sqllevel":
                    odbcdriver.SQLLevel = v;
                    break;

                case "usagecount":
                    odbcdriver.UsageCount = v;
                    break;

                case "cptimeout":
                    odbcdriver.CPTimeOut = v;
                    break;

                case "pdxuninstall":
                    odbcdriver.PdxUnInstall = v;
                    break;
                }
            }
            return(odbcdriver);
        }
Exemplo n.º 4
0
        public static OdbcDriver ParseForDriver(string driverName, Dictionary<string, string> data)
        {
            OdbcDriver odbcdriver = new OdbcDriver()
            {
                ODBCDriverName = driverName
            };

            // For each element defined for a typical Driver get
            // its value.
            foreach (var driverElement in data)
            {
                string v = driverElement.Value;
                switch (driverElement.Key.ToLower())
                {
                    case "apilevel":
                        odbcdriver.APILevel = v;
                        break;
                    case "connectfunctions":
                        odbcdriver.ConnectFunctions = v;
                        break;
                    case "driver":
                        odbcdriver.DriverDLL = v;
                        break;
                    case "driverodbcver":
                        odbcdriver.DriverODBCVer = v;
                        break;
                    case "fileextns":
                        odbcdriver.FileExtns = v;
                        break;
                    case "fileusage":
                        odbcdriver.FileUsage = v;
                        break;
                    case "setup":
                        odbcdriver.SetUp = v;
                        break;
                    case "sqllevel":
                        odbcdriver.SQLLevel = v;
                        break;
                    case "usagecount":
                        odbcdriver.UsageCount = v;
                        break;
                    case "cptimeout":
                        odbcdriver.CPTimeOut = v;
                        break;
                    case "pdxuninstall":
                        odbcdriver.PdxUnInstall = v;
                        break;
                }
            }
            return odbcdriver;
        }