Files
Common-VS2019/SacsStandardDbas/Dbas/Base/SaDbDfnOdbcDriver.cs
T
2021-05-05 15:36:28 +01:00

59 lines
1.8 KiB
C#

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<String,String> Attributes { get; } = new Dictionary<String, String>();
//-------------------------------------------------------------------
// Utilities.
/// <summary>Add 'Driver' attribute from registry. Fails if driver name not found.</summary>
public bool AddDriverConfig ()
{
if (StringUtil.IsEmpty(Name)) return false;
try
{
// 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;
}
}
catch (Exception) { }
return true;
}
//-------------------------------------------------------------------
}
//=======================================================================
}