>>>>Is there a way, within VFP, to enumerate installed OLEDB providers on a workstation?
>>>
>>>An MSKB article implies you need to query the registry, that's the approach I'll take unless someone has a better idea:
>>>
>>>
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q280739>>
>>That would be the way to do it, unless you find some ready-made code. Any entry under HKEY_CLASSES_ROOT\CLSID that has a key of OLEDB_SERVICES would represent an OLEDB provider. Once there, the sub-key named "OLE DB Provider" will have the description. HTH
>
>On further digging it looks like OLEDB already has sophisticated enumeration support:
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/oledb/htm/oledbenumerating_data_source_objects_and_enumerators.asp>
>It even has an example on how to enumerate providers; unhappily it's in C++. I have no idea if this functionality is available from VFP.
Al,
The information I gave you is only half true < s > because some OLEDB providers don't have the OLEDB_SERVICES entry in them. Upon further inspection and the thought that this might be something useful for the UT downloads, I was able to concoct a routine that returns an array with the available OLEDB providers using the registry access class that comes with VFP. The code is as follows:
#DEFINE HKEY_CLASSES_ROOT -2147483648
PARAMETERS aProviders
LOCAL oReg, lnErr, lcValue, lnCount, aKeys, aKeyVals, lFound
DIMENSION aProviders(1)
lnCount = 0
oReg = NEWOBJECT("registry", HOME()+"ffc\registry.vcx")
oReg.openkey("CLSID", HKEY_CLASSES_ROOT)
lnErr = oreg.enumkeys(@aKeys)
IF lnErr<>0 Then
RETURN lnErr
ENDIF
oReg.closekey
FOR Each arrElem In aKeys
aKeyVals = .f.
lFound = .f.
lnErr = oReg.openkey("CLSID\" + arrElem, HKEY_CLASSES_ROOT)
IF lnErr=0 Then
lnErr = oReg.enumkeys(@aKeyVals)
ENDIF
oReg.closekey
IF VARTYPE(aKeyVals)<>"L" Then
lFound = (ASCAN(aKeyVals, "OLE DB Provider") <> 0)
ENDIF
IF lFound then
lnErr = oReg.getregkey("", ;
@lcValue, ;
"CLSID\" + arrElem + "\OLE DB Provider", ;
HKEY_CLASSES_ROOT)
IF lnErr=0 Then
lnCount = lnCount + 1
IF lnCount>1 Then
DIMENSION aProviders(lnCount)
ENDIF
aProviders(lnCount) = lcValue
ENDIF
ENDIF
NEXT
RETURN 0
You would pass a variable by reference to this routine and it will get populated with the descriptions of the available OLEDB providers. If the first openkey call fails then it will return an error number right from the registry access class error numbers.
I tested with NT4 and W2K and it works fine. I will make a few more changes before posting it to the download section. Hope it helps!