March 2008
Intermediate to advanced
982 pages
22h 43m
English
You need a list of the ODBC drivers installed on the computer running your code.
Consult the registry.
The sample code uses the Microsoft.Win32.Registry class to display a list of all installed ODBC drivers.
The C# code in Program.cs in the project EnumerateOdbcDrivers is shown in Example 11-19.
Example 11-19. File: Program.cs for EnumerateOdbcDrivers solution
using System;
using Microsoft.Win32;
namespace EnuerateOleDbProviders
{
class Program
{
static void Main(string[] args)
{
// Get the HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers key.
RegistryKey keyLocalMachine = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", false);
// Retrueve and output the ODBC driver names
string[] valueNames = keyLocalMachine.GetValueNames( );
for (int i = 0; i < valueNames.Length; i++)
Console.WriteLine("{0}", valueNames[i]);
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey( );
}
}
}The output is shown in Figure 11-18.

Figure 11-18. Output for EnumerateOdbcDrivers solution
The .NET Framework classes that manipulate the registry are found in the Microsoft.Win32 namespace. The registry key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers contains a value name for each installed ODBC driver.
Read now
Unlock full access