Tuesday, April 11, 2017

laravel MS SQL connection with ENCRYPT=yes trustServerCertificate=true

I got a ubuntu docker container which runs php 5.5.9, laraverl 5.2 which can connect successfully to MS SQL server and get results back.

The docker image I am using is https://hub.docker.com/r/h2labs/laravel-mssql/

The problem I got is that the server uses encryption and I cant find how to pass the following parameters to the laravel connection string for mssql

ENCRYPT=yes;trustServerCertificate=true

My SQL SERVER connection string at present looks like this

DB_CONNECTION=sqlsrv
DB_HOST=sql.mydomain.com
DB_PORT=1433
DB_DATABASE=mydbname
DB_USERNAME=mysusername
DB_PASSWORD=mypass

My laravel database config looks like this

        'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
    ],

The MS SQL server error log entry is

Encryption is required to connect to this server but the client library does not support encryption; the connection has been closed. Please upgrade your client library. [CLIENT: 103.31.114.56]



via Mav Peri

Advertisement