Requirement: When the login module in winform is displayed, the ODBC Service list must be provided for the user to select.
Implementation Method: use the registry class provided by Microsoft. Win32 to access the system registry to obtain the ODBC Data Service list.
Specific implementation:
Microsoft. Win32 provides the registrykey class to access the registry of the system.
/// Define the registry sub-Path
String strregpath = @ "SOFTWARE \ ODBC. ini \ ODBC Data Sources ";
/// Create two registrykey classes. One Class points to the root path and the other class points to the sub-path.
Registrykey regrootkey;
Registrykey regsubkey;
/// Define root to point to the Registry HKEY_LOCAL_MACHINE Node
Regrootkey = registry. localmachine;
/// The registry enumeration class provides the following types
/*
Registry. classesroot --------------> Point to the hkey_classes_root node of the Registry.
Registry. currentconfig --------------> Point to the Registry hkey_current_config Node
Registry. currentuser --------------> Point to the Registry HKEY_CURRENT_USER Node
Registry. dyndata --------------> Point to the Registry hkey_dyn_data node (Dynamic registry data)
Registry. localmachine --------------> Point to the Registry HKEY_LOCAL_MACHINE Node
Registry. performancedata --------------> Point to the Registry hkey_performance_data Node
Registry. Users --------------> Point to the Registry HKEY_USERS Node
*/
Regsubkey = regrootkey. opensubkey (strregpath );
String [] strdsnlist = regsubkey. getvaluenames ();
/// Close
Regsubkey. Close ();
Regrootkey. Close ();
In this way, the reading of the DSN service list is realized.