/// <summary> /// Returns the Data Source Name (DSN) entries as array of /// ODBCDSN objects. /// </summary> /// <returns>Array of DSNs based on the baseKey parameter</returns> private static OdbcDsn[] GetDsnList(RegistryKey baseKey) { ArrayList dsnList = new ArrayList(); OdbcDsn[] odbcDSNs = null; if (baseKey == null) return null; // Get the key for (using the baseKey parameter passed in) // "\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\" (DSN_LOC_IN_REGISTRY) // that contains all the configured Data Source Name (DSN) entries. RegistryKey dsnNamesKey = OpenComplexSubKey(baseKey, DSN_LOC_IN_REGISTRY, false); if (dsnNamesKey != null) { // Get all DSN entries defined in DSN_LOC_IN_REGISTRY. string [] dsnNames = dsnNamesKey.GetValueNames(); if (dsnNames != null) { // Foreach DSN entry in the DSN_LOC_IN_REGISTRY, goto the // Key ODBC_INI_LOC_IN_REGISTRY+dsnName and get elements of // the DSN entry to create ODBCDSN objects. foreach (string dsnName in dsnNames) { // Get ODBC DSN object. OdbcDsn odbcDSN = GetDsn(baseKey, dsnName); if(odbcDSN != null) dsnList.Add(odbcDSN); } if (dsnList.Count>0) { // Create ODBCDSN objects equal to number of valid objects // in the DSN ArrayList. odbcDSNs = new OdbcDsn[dsnList.Count]; dsnList.CopyTo(odbcDSNs,0); } } dsnNamesKey.Close(); } return odbcDSNs; }
public static OdbcDsn ParseForOdbcDsn(string dsnName, string dsnDriverName, string[] dsnElements, string[] dsnElmVals) { OdbcDsn odbcdsn = null; if (dsnElements != null && dsnElmVals != null) { int i=0; string description = null; string server = null; string driver = null; string database = null; // For each element defined for a typical DSN get // its value. foreach (string dsnElement in dsnElements) { switch (dsnElement.ToLower()) { case "description": description = dsnElmVals[i]; break; case "server": server = dsnElmVals[i]; break; case "driver": driver = dsnElmVals[i]; break; // case "driverid": // case "safetransactions": // case "uid": case "database": case "dbq": database = dsnElmVals[i]; break; } i++; } odbcdsn = new OdbcDsn(dsnName, dsnDriverName, description, server, driver, database); } return odbcdsn; }