C#ODBC对话框

时间:2020-03-05 18:53:56  来源:igfitidea点击:

有关如何显示" ODBC连接"对话框并取回所选ODBC的任何信息?

解决方案

回答

好的,因为似乎没人能回答,如何通过DBSource遍历ODBC连接,即SQLServer或者MySQL

回答

// a_RootKey is Microsoft.Win32.RegistryKey 
// DSN is a class not provided in this code sample - you can see what properties are needed from the usage below.

List<DSN> DsnList = new List<DSN>();

Microsoft.Win32.RegistryKey SearchKey = a_RootKey.OpenSubKey("SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources");

if (SearchKey != null)
{

    foreach (string DsnName in SearchKey.GetValueNames() )
    {    
        if ( (string)SearchKey.GetValue(DsnName) == "SQL Server" )
        {
            Microsoft.Win32.RegistryKey anotherkey  = a_RootKey.OpenSubKey("SOFTWARE\ODBC\ODBC.INI\" + DSNName);
            DSN dsn = new DSN();
            dsn.Name = DSNName;
            dsn.Server = (string)anotherkey.GetValue("Server");
            dsn.Database = (string)anotherkey.GetValue("Database");
            dsn.Driver = (string)anotherkey.GetValue("Driver");

            DsnList.Add(dsn);
        }

    }
}
return DsnList;