Driver not specified for this database connection I want to connect to external database:

$old_database = array (
        'default' =&gt;    array (
                'database' =&gt; 'grantexpert_registration',
                'username' =&gt; 'grantexpert_usr',
                'password' =&gt; 'xxxxxx',
                'host' =&gt; '62.168.127.59',
                'port' =&gt; '5432',
                'driver' =&gt; 'pgsql',
                'prefix' =&gt; '',
        ),
);

Database::addConnectionInfo('olddatabase', 'default', $old_database);
db_set_active('olddatabase');


But Im getting an error:


  Driver not specified for this database connection: olddatabase in Database::openConnection()


All the examples show exactly this structure of array, but it's not working. Is smoething wrong here?
You've already provided the target DB name with the second param to addConnectionInfo(), so you just need to remove the 'default' element from the array, and shift the connection params up:

$old_database = array (
  'database' =&gt; 'grantexpert_registration',
  'username' =&gt; 'grantexpert_usr',
  'password' =&gt; 'xxxxxx',
  'host' =&gt; '62.168.127.59',
  'port' =&gt; '5432',
  'driver' =&gt; 'pgsql',
  'prefix' =&gt; '',
);

Database::addConnectionInfo('olddatabase', 'default', $old_database);
db_set_active('olddatabase');