# SQLServer Connection

**URL:** <https://discourse.cakephp.org/t/sqlserver-connection/7680>\
**Category:** Need Help\
**Created:** [April 19, 2020, 10:37pm UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680 "2020-04-19T22:37:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dantedantas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dantedantas/32/1770_2.png) [@dantedantas](https://discourse.cakephp.org/u/dantedantas)\
**Post date:** [April 19, 2020, 10:37pm UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/1 "2020-04-19T22:37:01Z")

</div>

Hello,  
Please, could someone help me to connect my CakePHP 4.0.5 with a SQL Server 2018?  
I am completely new with CakePHP and I confess that I am lost.

Environment:

- CakePHP 4.0.5
- SQL Server 2018
- XAMP (Apache + PHP7.4.4)

Message error that I am getting:  
“CakePHP is NOT able to connect to the database.  
Connection to Sqlserver could not be established: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].”

Connection code:

> ```
> 'default' => [
> 'className' => 'Cake\Database\Connection',
> 'driver' => 'Cake\Database\Driver\Sqlserver',
> 'persistent' => false,
> 'host' => 'MYSERVER:1433/MSSQLSERVER',
> 'username' => 'sa',
> 'password' => 'abcde',
> 'database' => 'myDB',
> 'prefix' => '',
> 'encoding' => PDO::SQLSRV_ENCODING_UTF8,
> 'timezone' => ‘UTC’,
> 'flags' => [],
> 'cacheMetadata' => true,
> 'log' => false     
> ],
> 
> ```

Thank you very much.

Best regards,  
Dante

---

<div class="post-metadata">

**Author:** ![anon81960487](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@anon81960487](https://discourse.cakephp.org/u/anon81960487)\
**Post date:** [April 19, 2020, 11:36pm UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/2 "2020-04-19T23:36:23Z")

</div>

Make sure you have your database configured properly, or I would suggest trying another database system.

Here is the info about database support with CakePHP: [https://book.cakephp.org/4/en/orm/database-basics.html#supported-databases](https://book.cakephp.org/4/en/orm/database-basics.html#supported-databases) it mentiones support for SQL Server, but it might not have great support.

MySQL and MariaDB work really well, but otherwise I have no expirence with SQL Server.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 20, 2020, 1:01am UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/3 "2020-04-20T01:01:54Z")

</div>

These things are almost always firewalls or permissions issues on the database server (e.g. not allowing connections from the system your PHP code is running on).

---

<div class="post-metadata">

**Author:** ![dantedantas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dantedantas/32/1770_2.png) [@dantedantas](https://discourse.cakephp.org/u/dantedantas)\
**Post date:** [April 20, 2020, 7:53am UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/4 "2020-04-20T07:53:15Z")

</div>

Thanks for the advice.  
I tested with MySQL and it works fine.  
About the SQLServer, we have an old system and I need to connect to a DB that we are using already.

---

<div class="post-metadata">

**Author:** ![dantedantas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dantedantas/32/1770_2.png) [@dantedantas](https://discourse.cakephp.org/u/dantedantas)\
**Post date:** [April 20, 2020, 7:55am UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/5 "2020-04-20T07:55:41Z")

</div>

Hi @Zuluru,  
thank you.

I think so too. It is a server here in my company. I will contact the support center.

---

<div class="post-metadata">

**Author:** ![dantedantas](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dantedantas/32/1770_2.png) [@dantedantas](https://discourse.cakephp.org/u/dantedantas)\
**Post date:** [April 20, 2020, 9:08pm UTC](https://discourse.cakephp.org/t/sqlserver-connection/7680/6 "2020-04-20T21:08:44Z")

</div>

Issue solved.

```
'default' => [
    'className' => 'Cake\Database\Connection',
    'driver' => 'Cake\Database\Driver\Sqlserver',
    'persistent' => false,
    'host' => 'MYSERVER',
    'port' => 1433,
    'username' => 'sa',
    'password' => '123456',
    'database' => 'MYDB',
    'prefix' => '',
    'encoding' => PDO::SQLSRV_ENCODING_UTF8,
    'flags' => [],
    'cacheMetadata' => true,
    'log' => false  
],
```
