Files
Common-VS2019/SacsStandardDbas/Dbas/Base/SaDbDfnOdbcDriver.cs
T
2024-02-27 15:45:02 +00:00

61 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
{
#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;
}
//-------------------------------------------------------------------
}
//=======================================================================
}