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

fikri1510's avatar

SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'myusername'.

I have been gooling for days, but I am still unable to get laravel connected to sql server. I followed what ppl in stackoverflow and laracast say, but it's still not successful What I did so far was

  1. I have changed in .env as
DB_CONNECTION=sqlsrv
DB_HOST=WINDOWS7\SQLSRV
DB_PORT=1433
DB_DATABASE=dblaravel
DB_USERNAME=myusername
DB_PASSWORD=my@password
  1. and in database.php as
'default' => env('DB_CONNECTION', 'sqlsrv'),
  1. and
'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ],

but still get this error

In Connection.php line 664:

  SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'myusername'. (SQL: select * fr
  om sysobjects where type = 'U' and name = migrations)


In Connector.php line 67:

  SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'myusername'.

I have changed TCP/IP Dynamic port to 1433 and restart in SQL Server Configuration Manager, but still get error.

What could probably wrong?I am new to sql server

The authentication I am using in sql management studio is windows7 and the mode is Windows and SQL

0 likes
17 replies
naet's avatar

Have you checked php extension: the sqlsrv and pdo_sqlsrv module ?

Make sure the sqlsrv module is loaded before pdo_sqlsrv.

munazzil's avatar

You have to change as below database.php configuration.You have kept as 'forge'.

    'database' => env('DB_DATABASE', 'dblaravel'),
        'username' => env('DB_USERNAME', 'myusername'),
        'password' => env('DB_PASSWORD', 'my@password'),
Osama_Khalid's avatar

it will be used only if not they are not given in env file. And as you see from his error 'myusername' is being used

martleby's avatar

I had this exact same problem. Having checked:

-That SQL Server was configured correctly.

-That the drivers were installed correctly (I'm on Windows using the MS PHP drivers).

-That the connection details were correct in PHP.

-The SQL Server log file.

and pulled my hair out...

... I found that the problem was that the password must be quoted in the .env file. ie:

DB_PASSWORD="mypassword"

and NOT

DB_PASSWORD=mypassword

6 likes
Tnr1112's avatar

You saved me a lot of time. Love u <3

lovelypuspen's avatar

@martleby this technique worked for me, keeping password inside quote

sql server is in centos \n apache server is in windows,

Gabo57's avatar

@martleby Thanks. I already had a day and a half with this problem. Weird thing I had another XAMPP installation and it worked for me without " " Thanks again...

Reejesh's avatar

Check if the host name is correct, usually windows shared servers have host at one ip and files at another ip, so don't use localhost in env files, check with the provider and get the correct ip of the database server and check the connection again. You can check the ip from plesk panel.

jumah's avatar

it's too late that I am answering.

I had the same issue with SQL server, I did everything but not succeed to connect unit I removed the 1344 port. and let the port empty. now it works fine for me.

6 likes
tobyallen's avatar

Removing the Port from the .env file also worked for me.

1 like
gonzalg's avatar

If you are using AD to authenticate, try using 'uid' and 'pwd' instead of 'username' and 'password' in the connection info, for example:

       'sqlsrv' => array(
            'driver'   => 'sqlsrv',
            'host'     => 'sql_server_host',
            'database' => 'sql_server_db',
//            'username' => 'domain\username',
//            'password' => 'password',
            'uid' => 'domain\username',
            'pwd' => 'password'
)

Please or to participate in this conversation.