# DB Connection succeeds for one model, but fails for second model

**URL:** <https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164>\
**Category:** Need Help\
**Created:** [April 13, 2018, 12:27am UTC](https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164 "2018-04-13T00:27:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://discourse.cakephp.org/u/kevin)\
**Post date:** [April 13, 2018, 12:27am UTC](https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164/1 "2018-04-13T00:27:37Z")

</div>

Hi all

We have a project which has a number of db connections. In one model, we have a database connection, and I’m able to query, create rows, etc just fine.

I enter a different model, which references a different table on the same database connection, and when I try a very basic query:

```
$this->ModelName->find('all', [] ); 

```

And I get an error:

```
A Database connection using "DatabaseName" was missing or unable to connect.
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (﻿SQLVM-ADAM.local) (severity 9)

```

How would you go about troubleshooting this? I’m stumped.

Thanks,  
Kevin

---

<div class="post-metadata">

**Author:** ![patsuckow](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/patsuckow/32/992_2.png) [@patsuckow](https://discourse.cakephp.org/u/patsuckow)\
**Post date:** [April 13, 2018, 1:35pm UTC](https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164/2 "2018-04-13T13:35:23Z")

</div>

And you used `$this->loadModel` ?:

example in AdminsController:

```
$this->loadModel('Users');
$all_users = $this->Users->find();

```

?

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://discourse.cakephp.org/u/kevin)\
**Post date:** [April 13, 2018, 11:14pm UTC](https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164/3 "2018-04-13T23:14:41Z")

</div>

Yep, a loaded the model.

In the end I got the datasource from the working model and called fetchAll on that.

Very strange.

---

<div class="post-metadata">

**Author:** ![patsuckow](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/patsuckow/32/992_2.png) [@patsuckow](https://discourse.cakephp.org/u/patsuckow)\
**Post date:** [April 14, 2018, 8:34am UTC](https://discourse.cakephp.org/t/db-connection-succeeds-for-one-model-but-fails-for-second-model/4164/4 "2018-04-14T08:34:27Z")

</div>

you can bring all the code of the action in which it happens, so that I looking… ?
