using Microsoft.Win32; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sarand.Net.Standard.Dbas.Base { //======================================================================= public class SaDbDfnOdbcDriver { //------------------------------------------------------------------- // Data members. //------------------------------------------------------------------- // Construction. public SaDbDfnOdbcDriver(String name) { Name = name; } //------------------------------------------------------------------- // Properties. public String Name { get; } public Dictionary Attributes { get; } = new Dictionary(); //------------------------------------------------------------------- // Utilities. /// Add 'Driver' attribute from registry. Fails if driver name not found. public bool AddDriverConfig() { if (StringUtil.IsEmpty(Name)) return false; try { #pragma warning disable CA1416 // Retrieve 'Driver' (location of DLL) parameter for this driver: using (RegistryKey localMachineHive = Registry.LocalMachine) using (RegistryKey odbcDriverKey = localMachineHive.OpenSubKey(@"SOFTWARE\ODBC\ODBCINST.INI\" + Name)) { if (odbcDriverKey != null) { object driverName = odbcDriverKey.GetValue("Driver"); if (driverName != null && driverName is String) Attributes["Driver"] = driverName.ToString(); } return true; } #pragma warning restore CA1416 } catch (Exception) { } return true; } //------------------------------------------------------------------- } //======================================================================= }