/// <summary> /// Method that gives the ODBC Drivers installed in the local machine. /// </summary> /// <returns></returns> public static ODBCDriver[] GetODBCDrivers() { ArrayList driversList = new ArrayList(); ODBCDriver[] odbcDrivers = null; // Get the key for // "KHEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers\\" // (ODBC_DRIVERS_LOC_IN_REGISTRY) that contains all the drivers // that are installed in the local machine. RegistryKey odbcDrvLocKey = OpenComplexSubKey(Registry.LocalMachine, ODBC_DRIVERS_LOC_IN_REGISTRY, false); if (odbcDrvLocKey != null) { // Get all Driver entries defined in ODBC_DRIVERS_LOC_IN_REGISTRY. string [] driverNames = odbcDrvLocKey.GetValueNames(); odbcDrvLocKey.Close(); 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) { driversList.Add(odbcDriver); } } if (driversList.Count > 0) { // Create ODBCDriver objects equal to number of valid objects // in the ODBC Drivers ArrayList. odbcDrivers = new ODBCDriver[driversList.Count]; driversList.CopyTo(odbcDrivers, 0); } } } return(odbcDrivers); }
/// <summary> /// Method thar returns driver object based on the driver name. /// </summary> /// <param name="driverName"></param> /// <returns>ODBCDriver object</returns> public static ODBCDriver GetODBCDriver(string driverName) { int j = 0; ODBCDriver odbcDriver = null; string [] driverElements = null; string [] driverElmVals = null; RegistryKey driverNameKey = null; // Get the key for ODBCINST_INI_LOC_IN_REGISTRY+dsnName. driverNameKey = OpenComplexSubKey(Registry.LocalMachine, ODBCINST_INI_LOC_IN_REGISTRY + driverName, false); if (driverNameKey != null) { // Get all elements defined in the above key driverElements = driverNameKey.GetValueNames(); // Create Driver Element values array. driverElmVals = new string[driverElements.Length]; // For each element defined for a typical Driver get // its value. foreach (string driverElement in driverElements) { driverElmVals[j] = driverNameKey.GetValue(driverElement).ToString(); j++; } // Create ODBCDriver Object. odbcDriver = ODBCDriver.ParseForDriver(driverName, driverElements, driverElmVals); driverNameKey.Close(); } return(odbcDriver); }
public static ODBCDriver ParseForDriver(string driverName, string[] driverElements, string[] driverElmVals) { ODBCDriver odbcdriver = null; if (driverElements != null && driverElmVals != null) { string apilevel = null; string connectfunctions = null; string driver = null; string driverodbcver = null; string fileextns = null; string fileusage = null; string setup = null; string sqllevel = null; string usagecount = null; string cptimeout = null; string pdxuninstall = null; int i = 0; // For each element defined for a typical Driver get // its value. foreach (string driverElement in driverElements) { switch (driverElement.ToLower()) { case "apilevel": apilevel = driverElmVals[i].ToString(); break; case "connectfunctions": connectfunctions = driverElmVals[i].ToString(); break; case "driver": driver = driverElmVals[i].ToString(); break; case "driverodbcver": driverodbcver = driverElmVals[i].ToString(); break; case "fileextns": fileextns = driverElmVals[i].ToString(); break; case "fileusage": fileusage = driverElmVals[i].ToString(); break; case "setup": setup = driverElmVals[i].ToString(); break; case "sqllevel": sqllevel = driverElmVals[i].ToString(); break; case "usagecount": usagecount = driverElmVals[i].ToString(); break; case "cptimeout": cptimeout = driverElmVals[i].ToString(); break; case "pdxuninstall": pdxuninstall = driverElmVals[i].ToString(); break; } i++; } odbcdriver = new ODBCDriver(driverName, apilevel, connectfunctions, driver, driverodbcver, fileextns, fileusage, setup, sqllevel, usagecount, cptimeout, pdxuninstall); } return(odbcdriver); }