Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

hello all!

I need to retrive the physical path of the DB having the DSN. My Db is ms access *.mdb , the DSN is a system one.

I tried with
Win32::ODBC->GetDSN($dsn)
but the associtive array contain only the driver

any idea?
thanks lorenzo*

Replies are listed 'Best First'.
Re: problem with Win32::ODBC
by BrowserUk (Patriarch) on Sep 11, 2002 at 14:01 UTC

    As hiseldl says, you may find this information, in the registry, but if Win32::ODBC::getDSN() isn't returning the DBQ key, it may well be that this information is not available there. I'm not sure about the circumstances when this occurs, but, for example, on my system I have the remnents of a couple DSN's that was set up by the installs of some peices of software now long gone which don't have an DBQ entries. However, there is an entry in the registry HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\odbc.ini\ODBC File DSN\DefaultDSNDir which points to (on my system) D:\Program Files\Common Files\ODBC\Data Sources. In this directory I have a couple of files, an example of which is Authors.dsn containing:

    ODBC] DRIVER=Microsoft Access Driver (*.mdb) UID=admin UserCommitSync=Yes Threads=3 SafeTransactions=0 PageTimeout=5 MaxScanRows=8 MaxBufferSize=512 ImplicitCommitSync=Yes FIL=MS Access DriverId=25 DefaultDir=D:\Inetpub\iissamples\sdk\asp\database DBQ=D:\Inetpub\iissamples\sdk\asp\database\Authors.mdb
    with the last line being the info that you are interested in.

    One final caveat. If the DSN you are using is a so-called 'System DSN', ie. one that lives outside of your box on a server somewhere, the DBQ information will probably not be available to you through any normal programable mechanism. This is a standard security feature.


    Well It's better than the Abottoire, but Yorkshire!
Re: problem with Win32::ODBC
by hiseldl (Priest) on Sep 11, 2002 at 13:38 UTC
    Try looking in the registry, here's where you can find an entry, look at the "DBQ" value for the full path:

    [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\myDSN]
    "Driver"="C:\\WINNT\\System32\\odbcjt32.dll"
    "DBQ"="C:\\Documents and Settings\\mydir\\DATA\\mydatabase.MDB"
    "DriverId"=dword:00000019
    "FIL"="MS Access;"
    "SafeTransactions"=dword:00000000
    "UID"=""
    

    --
    hiseldl
    "Act better than you feel"

      many thanks,
      the access to the registry is a little bit obscure but it seems work..
      It works with system dsn too...
      here my resulting code:
      use Win32::TieRegistry ( Delimiter=>"/" );
      
      $dsn="testDSN";
      $odbc= $Registry->{"HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.INI/$dsn/"}or  die "$^E\n";
      
      print $odbc->{DBQ}or die $!;
      

      I hope some day I can help someone in the same way you helped me.
      ciao lorenzo*