Here is the code that I use to get a SortedList of all the DSN names
from the registry...
<code>
/// <summary>
/// Reads the local user/system DSN registry entries and returns a
SortedList of Data Source Names.
/// </summary>
/// <remarks>In the event that a DSN exists in both the User and System
registries,
/// the User DSN takes precedence over the System DSN.</remarks>
/// <returns>The SortedList of Data Source Names</returns>
/// <seealso cref="System.Collections.SortedList"></seealso>
public static SortedList listAllDSN()
{
SortedList allDSN = new SortedList();
// Get User DNS Names
RegistryKey reg = (Registry.CurrentUser).OpenSubKey("Software");
reg = reg.OpenSubKey("ODBC");
reg = reg.OpenSubKey("ODBC.INI");
reg = reg.OpenSubKey("ODBC Data Sources");
if (reg != null)
{
// Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
foreach ( string s in reg.GetValueNames() )
{
allDSN.Add( s , null );
}
}
try
{
reg.Close();
}
catch ( System.Exception ex )
{
}
// Get System DNS Names
reg = (Registry.LocalMachine).OpenSubKey("Software");
reg = reg.OpenSubKey("ODBC");
reg = reg.OpenSubKey("ODBC.INI");
reg = reg.OpenSubKey("ODBC Data Sources");
if (reg != null)
{
// Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
foreach ( string s in reg.GetValueNames() )
{
try
{
allDSN.Add( s , null );
}
catch ( System.Exception ex )
{
}
}
}
try
{
reg.Close();
}
catch ( System.Exception ex )
{
}
return allDSN ;
}
</code>
Joel