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

Armed with a ODBC data source name of a sql server database, i'm trying to find out which default database the dsn is using. is there an easy way to do this? i'm using winNT/2K with activestate perl and dbi. thanks so much. michael

Replies are listed 'Best First'.
Re: dsn and underlying db
by CubicSpline (Friar) on Jun 28, 2002 at 17:28 UTC
    Hey AM, I can think of two ways of doing this.

    The first would be to actually connect to the DSN and use the "Name" DBI database handle property to find out which database you are connected to. For example:

    $dbh = DBI->connect("dbi:ODBC:DSN","user","passwd"); print "Connected to: ", $dbh->{"Name"};
    The other option is a non-perl route and doesn't require connecting to the database at all. You should be able to find out the default database by going through the Windows Registry.

    I'm running Windows 2000 and the path to my DSNs is:
    HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\
    Choose your DSN and there should be a "Database" string value for that key.

    HTH

    ~CubicSpline
    "No one tosses a Dwarf!"

      The other option is a non-perl route and doesn't require connecting to the database at all. You should be able to find out the default database by going through the Windows Registry.

      Well, that doesn't have to be a none non-perl way ... see Win32::TieRegistry.

      -- Hofmator