Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine ODBC Driver
Message
From
23/08/2006 15:23:18
 
 
To
22/08/2006 16:11:28
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01147705
Message ID:
01147988
Views:
20
>Many years ago I had the code to do this, but seemed to have misplaced it... I am trying to get the ODBC driver for a specific data source. Basically, I am trying to determine whether a given ODBC data source is Access, FoxPro, SQL, or Oracle on the fly. It was only 3-4 lines of code, but for the life of me I can't find it. I remember that I used to determine Access if "mdb" was in the driver name and VFP if "fox" was in the driver name. Any help would be greatly appreciated...

Well, this is a bit longer than 3-4 lines, but it works for me. Part of what makes it longer is that when I did this, I wanted only the "User DSN" stuff, and there doesn't seem to be a simple way to get at it. I had to pull all the stuff, and then pull the system/file dsn's and then subtract. Anyway, for what it's worth, here is something that should get it off the ground.

It will not surprise me in the least if there is a simpler way to do this (at least to get only 'user dsn' information)
#include "registry.h"

** class in vfp9 samples directory
SET PROCEDURE TO HOME(2) + "classes\registry.prg"

* oOdbcReg to get odbc info, oReg to do general registry
LOCAL oOdbcReg as OdbcReg, oReg as Registry

** set up some working arrays and variables
LOCAL ARRAY aAll[1], aSome[1], aDsn[1]
LOCAL lnCount, lnInc, llOk, lcVal

CLEAR

** odbc specific registry handling
oOdbcReg = CREATEOBJECT("OdbcReg")
** general registry handling
oReg = CREATEOBJECT("Registry")

* I want only user dsn's but there doesn't seem to be a direct
* way to get them so I have to get everything, then get the
* system and file dsns and subtract

** get list of all user,system and file dsns
llOk = (oOdbcReg.getodbcdrvrs(@aAll, .T.) = 0)
IF llOk		&& get list of system and file dsns only
  llOk = (oOdbcReg.GetOdbcdrvrs(@aSome, .F.) = 0)
ENDIF

IF llOk
  lnInc = 0
  FOR lnCount = 1 TO ALEN(aAll)
    ** is this one (system or file) in the everything array?
    IF ASCAN(aSome, aAll[lnCount]) = 0
      ** it is not, so add it to my user dsn array
      lnInc = lnInc + 1
      DIMENSION aDsn[lnInc]
      aDsn[lnInc] = aAll[lnCount]
    ENDIF
  ENDFOR

  IF !EMPTY(aDsn[1])	&& we have at least one
    ** get the value of the dsn key in the current user odbc list
    FOR lnCount = 1 TO ALEN(aDsn)
      lcVal = SPACE(100)	&& info holder
      oReg.GetRegkey(aDsn[lnCount],@lcVal, ;
          "Software\ODBC\ODBC.INI\ODBC Data Sources", ;
          HKEY_CURRENT_USER)
      IF "*.dbf" $ lcVal	&& contains '.dbf'?
        ** yes, so display the key and the value
        ? aDsn[lnCount], '"' + lcVal + '"'
      ENDIF
    ENDFOR
  ELSE
    MESSAGEBOX("Nothing Found")
  ENDIF
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform