2016-06-10 67 views

回答

0

我試試這段代碼。

我不知道現在是否適用於所有32位和64位提供商

的GuidCLSID OLEDBC8B522D0-5CF3-11ce-ADE5-00AA0044773D

internal static Guid IID_IUnknown = new Guid("00000000-0000-0000-c000-000000000046"); 
internal static Guid CLSID_DataLinks = new Guid("2206CDB2-19C1-11d1-89E0-00C04FD7A829"); 
internal static Guid CLSID_OLEDB_ENUMERATOR = new Guid("C8B522D0-5CF3-11ce-ADE5-00AA0044773D"); 
internal static Guid CLSID_MSDASQL_ENUMERATOR = new Guid("C8B522CD-5CF3-11ce-ADE5-00AA0044773D"); 


private string GetOLEDBProvidersRegistered() 
{ 
    var res = ""; 
    try 
    { 
     Guid guidOleDbEnum = new Guid("{C8B522D0-5CF3-11ce-ADE5-00AA0044773D}"); 

     Type type = Type.GetTypeFromCLSID(guidOleDbEnum); 

     using (OleDbDataReader rdr = OleDbEnumerator.GetEnumerator(type)) 
     { 
      while (rdr.Read()) 
       //Console.WriteLine("{0} - {1}", rdr["SOURCES_NAME"], rdr["SOURCES_DESCRIPTION"]); 
       res += string.Format("{0} - {1}\r\n", rdr["SOURCES_NAME"], rdr["SOURCES_DESCRIPTION"]); 

     } 
    } 
    catch (Exception ex) 
    { 
     res = ex.Message; 
    } 
    return res; 
} 
相關問題