How can I connect to MS SQL and Oracle databases from Perl when the credentials are stored in a separate file?
<p>I am on a RedHat machine with the Unix ODBC drivers installed. I have used a construct like the following to connect to MySQL databases for a long time:</p>

<pre><code>my @connection_userTracking = (
    "DBI:mysql:;" 
        . "mysql_read_default_file=/var/www/.my.cnf;" 
        . "mysql_read_default_group=myProject",
    undef,
    undef,
    {   PrintError =&gt; 0,
        RaiseError =&gt; 1,
        AutoCommit =&gt; 1
    }
);
</code></pre>

<p>This lets me store my database credentials in a separate file instead of hard-coding them in my Perl script. I assume that there must be something similar for MS SQL and Oracle. What is the format of the connection string for each?</p>

<p>I tried:</p>

<pre><code>my @connection_MSSQL = (
    "DBI:ODBC:;" 
        . "mysql_read_default_file=/var/www/.my.cnf;" 
        . "mysql_read_default_group=myProjectMSSQL",
    undef,
    undef,
    {   PrintError =&gt; 0,
        RaiseError =&gt; 1,
        AutoCommit =&gt; 1
    }
);
</code></pre>

<p>with the DSN, username, and password in the config file but it barfs with the message: </p>

<blockquote>
  <p>failed: [unixODBC][Driver Manager]Data source name not found, and no default driver specified</p>
</blockquote>

<p>I added the DSN back to the code making the first line</p>

<pre><code>"DBI:ODBC:DSN=my.db.host.com;"
</code></pre>

<p>and that barfs as well with the error</p>

<blockquote>
  <p>failed: [unixODBC][FreeTDS][SQL Server]Login failed for user ''</p>
</blockquote>

<p>I am not an expert with Linux ODBC so perhaps it is possible to put usernames and passwords in the system odbc.ini file but I don't like that. I would rather have project-specific files.</p>

<p>Is this sort of thing possible for MS SQL and Oracle?</p>