Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

michalis's avatar

problem connecting to mssql (laradoc & octobercms)

Hey guys, found this other thread with the same issue

https://laracasts.com/discuss/channels/laravel/cannot-connect-to-mssql-laradock

it says alias is missing from network in docker-compose.yml

but whe i enter an alias it gives me an error Array is required. Scalar value not allowed

docker-compose.yml

### MSSQL ################################################
    mssql:
      build:
        context: ./mssql
      environment:
        - MSSQL_PID=Express
        - MSSQL_DATABASE=${MSSQL_DATABASE}
        - SA_PASSWORD=${MSSQL_PASSWORD}
        - ACCEPT_EULA=Y
      volumes:
        - mssql:/var/opt/mssql
      ports:
        - "${MSSQL_PORT}:1433"
      networks:
        backend
          aliases:
            -mssql

this is in the laradocs .env:

### MSSQL #################################################

MSSQL_DATABASE=mssql
MSSQL_PASSWORD="mssql"
MSSQL_PORT=1433

this is in the laravel .env, not sure what to put as username though:

DB_CONNECTION=sqlsrv
DB_HOST=mssql
DB_PORT=1433
DB_DATABASE=mssql
DB_USERNAME=root
DB_PASSWORD="mssql"

Im not sure what I am missing

EDIT PS** inspecting the network now, it does have mssql as alias, so that other thread is of not use

here is th error

[ERROR] Connection failed: SQLSTATE[HYT00]: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
0 likes
8 replies
Tray2's avatar

Is there a particular reason for using MS SqlServer?

If it's possible you should move to MySQL/MariaDB or PostgreSQL since they are all pretty much the standard for Laravel.

jpmg's avatar

Hello @michalis i have an sqlsrv connection work for me without problem. this are the steps.

  1. Install an ODBC sqlsrv driver in your pc. (if everything its ok)

  2. In my config\database.php (this is my code conexion)

     				'sqlsrv' => [
          						'driver' => 'sqlsrv',
          						'host' => IP ADDRES',
           						'database' => env('Database', 'DATABASENAME'),
           						'username' => env('UID', 'USERNAME'),
          						'password' => env('PWD', 'USERPASSWORD'),
     				],
    

I hope it work for you!!

1 like
michalis's avatar

@jpmg hi and thank you for taking the time, do you mean I should install an sql server outside of docker?

Sinnbeck's avatar

Make sure that the container is running. Your hostname should be correct as docker will connections on the service name (mssql), and you even alias it again with the same name.

Regarding the network. Its hard to tell without seeing your complete docker-compose.yml

1 like
michalis's avatar

@Sinnbeck the container is running indead, is there a way to find the reason for the timeout?

Sinnbeck's avatar

@michalis As you pointed out yourself, it could be due to being on another network. Or the mssql service isnt running inside the container for some reason. Perhaps you can try deletiing the container + volume, and create them again

Please or to participate in this conversation.