private static ODBCDSN GetDSN(RegistryKey baseKey, string dsnName) { int j = 0; string dsnDriverName = null; RegistryKey dsnNamesKey = null; RegistryKey dsnNameKey = null; string[] dsnElements = null; string[] dsnElmVals = null; ODBCDSN odbcDSN = null; // Get the key for (using the baseKey parmetre passed in) // "\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\" (DSN_LOC_IN_REGISTRY) // that contains all the configured Data Source Name (DSN) entries. dsnNamesKey = OpenComplexSubKey(baseKey, DSN_LOC_IN_REGISTRY, false); if (dsnNamesKey != null) { // Get the name of the driver for which the DSN is // defined. dsnDriverName = dsnNamesKey.GetValue(dsnName).ToString(); dsnNamesKey.Close(); } // Get the key for ODBC_INI_LOC_IN_REGISTRY+dsnName. dsnNameKey = OpenComplexSubKey(baseKey, ODBC_INI_LOC_IN_REGISTRY + dsnName, false); if (dsnNameKey != null) { // Get all elements defined in the above key dsnElements = dsnNameKey.GetValueNames(); // Create DSN Element values array. dsnElmVals = new string[dsnElements.Length]; // For each element defined for a typical DSN get // its value. foreach (string dsnElement in dsnElements) { dsnElmVals[j] = dsnNameKey.GetValue(dsnElement).ToString(); j++; } // Create ODBCDSN Object. odbcDSN = ODBCDSN.ParseForODBCDSN(dsnName, dsnDriverName, dsnElements, dsnElmVals); dsnNamesKey.Close(); } return(odbcDSN); }
/// <summary> /// ODBC DSN을 검색한다. /// </summary> private void DsnSearch(string sDSN) { try { ODBCDSN _dsn = GetUserDSN(sDSN); if (_dsn.GetDSNDriverName().IndexOf("MySQL") > -1) { sDBType = "MYSQL"; } else if (_dsn.GetDSNDriverName().IndexOf("SQL Server") > -1) { sDBType = "MSSQL"; } else { sDBType = ""; } if (sDBType.Equals("MYSQL")) { cbMaria.Enabled = true; } else { cbMaria.Enabled = false; cbMaria.Checked = false; } txtDsnDriver.Text = _dsn.GetDSNDriverName(); txtDB.Text = sDBType; } catch (Exception ex) { txtDsnDriver.Text = "등록되지 않은 DSN 정보 입니다."; txtDB.Text = "등록되지 않은 DSN 정보 입니다."; cbMaria.Checked = false; cbMaria.Enabled = false; } }
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; // 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; } i++; } odbcdsn = new ODBCDSN(dsnName, dsnDriverName, description, server, driver); } return(odbcdsn); }