# Class Cake\\Database\\Connection could not be found

**URL:** <https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826>\
**Category:** Need Help\
**Created:** [January 25, 2024, 6:02pm UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826 "2024-01-25T18:02:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/klaus/32/269_2.png) [@Klaus](https://discourse.cakephp.org/u/Klaus)\
**Post date:** [January 25, 2024, 6:02pm UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826/1 "2024-01-25T18:02:52Z")

</div>

Hi,  
I have a new cake application created 4.5.1  
The local development is connection without problems.  
On the server I get the error:

# Datasource class Cake\Database\Connection could not be found

This is may config in app.php:  
‘Datasources’ =\> [

```
    'default' => [
        'className' => Connection::class,
        'driver' => Mysql::class,
        'persistent' => false,
        'timezone' => 'UTC',
        'flags' => [],
        'cacheMetadata' => true,
        'log' => false,
        'quoteIdentifiers' => false,
    ],

```

In app\_local.php I have entered the login data.

The first access is raising the error:

```
public function home() {
    $this->log('PageController Home');
            $catTable = TableRegistry::get('Categories');
    $categorie = $catTable->find()
            ->where(['title' => 'Home'])
           ->toList();

    //dd($categorie[0]->id);
    $departTable =$this->getTableLocator()->get('Departments');
    $newcat = $departTable->find()
            ->where(['title' => 'HomeNews'])
            ->toList();

    $articles = $this->getTableLocator()->get('Articles');

    $homepage = $articles->find()
            ->where(['category_id' => $categorie[0]->id])
            ->order(['department_id' => 'ASC'])
            ->toArray();

    $news = $articles->find()
            ->where(['department_id' => $newcat[0]->id])
            ->toArray();

    $this->set(compact('homepage', 'news'));
}

```

On this server I have two other cake application running without problems. I compared the configuration and found the onla difference:

```
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',

```

But changing these settings brought no result.  
Where do I have to look further? What to check?  
Kind regards  
Klaus

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 26, 2024, 1:15pm UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826/2 "2024-01-26T13:15:54Z")

</div>

> [@Klaus](#):
>
> Datasource class Cake\Database\Connection could not be found

This feels weird because [cakephp/src/Database/Connection.php at 4.x · cakephp/cakephp · GitHub](https://github.com/cakephp/cakephp/blob/4.x/src/Database/Connection.php#L49) does indeed exist.

Also the fact that you use the class constant `Connection::class` means this class actually is present in your filesystem.

Maybe try giving us a full stacktrace if the error.

---

<div class="post-metadata">

**Author:** ![Klaus](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/klaus/32/269_2.png) [@Klaus](https://discourse.cakephp.org/u/Klaus)\
**Post date:** [January 28, 2024, 9:15am UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826/3 "2024-01-28T09:15:06Z")

</div>

Sure Kevin,

Request URL: /  
Client IP: 176.199.252.125  
2024-01-25 17:44:04 warning: DebugKit is disabling itself as your host `cake.verein-lebensalter.de` is not in the known safe list of top-level-domains (localhost, invalid, test, example, local). If you would like to force DebugKit on use the `DebugKit.forceEnable` Configure option.  
2024-01-25 17:44:04 error: AppController Init  
2024-01-25 17:44:04 error: PageController Init  
2024-01-25 17:44:04 error: PageController Home  
2024-01-25 17:44:04 error: [Cake\Datasource\Exception\MissingDatasourceException] Datasource class Cake\Database\Connection could not be found. in /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/ConnectionRegistry.php on line 57  
Exception Attributes: array (  
‘class’ =\> ‘Cake\Database\Connection’,  
‘plugin’ =\> NULL,  
)  
Stack Trace:

- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php:103
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/ConnectionManager.php:214
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:255
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/Locator/AbstractLocator.php:68
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:206
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/TableRegistry.php:95
- /var/www/web489/html/cakephp/src/Controller/PagesController.php:56
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/Controller.php:560
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:140
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:115
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/BaseApplication.php:325
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:86
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php:166
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Middleware/BodyParserMiddleware.php:157
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php:189
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php:68
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:149
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:67
- /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Server.php:99
- /var/www/web489/html/cakephp/webroot/index.php:40
- [main]:

Request URL: /  
Client IP: 176.199.252.125

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 28, 2024, 9:56am UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826/4 "2024-01-28T09:56:48Z")

</div>

This doesn’t make sense… This would mean if you do

```auto
var_dump(class_exists('Cake\Database\Connection'));

```

in your AppController initialize method it would return `false` - meaning something is wrong with your composer autoloader.

I’d recommend you re-install your vendor modules via

```auto
rm -rf vendor composer.lock
composer install --prefer-dist

```

---

<div class="post-metadata">

**Author:** ![Klaus](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/klaus/32/269_2.png) [@Klaus](https://discourse.cakephp.org/u/Klaus)\
**Post date:** [January 28, 2024, 1:04pm UTC](https://discourse.cakephp.org/t/class-cake-database-connection-could-not-be-found/11826/5 "2024-01-28T13:04:46Z")

</div>

Thanks Kevin,

I only made a local composer update und uploaded the vendor folder.  
Additional the composer.lock , and the rror is gone.  
The first upload of the application seams to produced the error.  
Regards Klaus
