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

ssquare's avatar

SQLSTATE[08001]: [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it. (SQL: select top 1 * from [settings] where [name] = site_title and [settings].[deleted_at] is null)

I am just trying to migrate my laravel to sql server. I have installed Miscrosoft SQL Server. I have downloaded SQL server developer version and make default basic installation.

I am using wamp 64 with php 7.2.4. I have added two extensions in php.ini after I copied them inside wamp64/bin/php/php7.2.4/ext/

extension=php_pdo_sqlsrv_72_ts_x64 extension=php_sqlsrv_72_ts_x64

Now, I can see pdo_sqlsrv in phpinfo.

I have created a database in MSSQL and updated .env file as

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-H9OGJE5\MSSQLSERVER
DB_PORT=1433
DB_DATABASE=kpi_db
DB_USERNAME=sa
DB_PASSWORD=

But, unfortunately I am getting this error when I tried to load. Also, I have tried to migrate through artisan command but with no success

   Illuminate\Database\QueryException  : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)

  at C:\wamp64\www\project\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("could not find driver")
      C:\wamp64\www\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:50

  2   PDOException::("could not find driver")
      C:\wamp64\www\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:46

  Please use the argument -v to see more details.

0 likes
32 replies
staudenmeir's avatar

Which error are you getting? The one from the title or "could not find driver"?

staudenmeir's avatar

You can't answer my question with "Yes.". Is the error "No connection could be made because the target machine actively refused it." or "could not find driver"?

ssquare's avatar

The one from the title I got it when I tried to access the site.

The last one I got when I tried to run php artisan migrate

ssquare's avatar

@staudenmeir Got following error

SQLSTATE[08001]: [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. (SQL: select top 1 * from [settings] where [name] = site_title and [settings].[deleted_at] is null)
technosml's avatar

@ssquare try this simple code and check it connects with mssql server:

$serverName = "serverName\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>```
staudenmeir's avatar

Put dd($this->getSqlSrvDsn($config)); in Illuminate\Database\Connectors\SqlServerConnector::getDsn(). What's the result?

ssquare's avatar

@technosml

Connection could not be established.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. [message] => [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )

I got above error. I have created database on sql server using (local). And I don't know I have which username and password on sqlserver I am using username 'sa' and black password as suggesting as default one.

By the way, I think instance name should be right as I have seen somewhere the name inside sqlserver should be its instance name

https://ibb.co/jkcSMe

technosml's avatar

Sorry @ssquare but I don't have much knowledge about MS SQL Server. But I think there will be any option to create a username and password for your databases. And I think you got the answer for your question. Please create new thread for your query about username and password. So that anyone can help you.

ssquare's avatar

@technosml okay i have created one user root and given password. and mapped to the database and also given the role as public. Now, what?

ssquare's avatar

@staudenmeir

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:MQ/MXLKOABVwvWjD3G9TgX1v4BO/+bWCez06cuzhYv8=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-H9OGJE5\MSSQLSERVER
DB_PORT=1433
DB_DATABASE=kpi_db
DB_USERNAME=sa
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

staudenmeir's avatar

What did you change after my post "Try an empty port: DB_PORT="?

2 likes
ssquare's avatar

@staudenmeir I have worked with that too. But with no success. Still returning.

"sqlsrv:Server=DESKTOP-H9OGJE5\MSSQLSERVER;Database=kpi_db"

If you could, I could also screen share with team viewer or so

staudenmeir's avatar

What did the .env file look like when you got "sqlsrv:Server=DESKTOP-H9OGJE5\MSSQLSERVER,1433;Database=kpi_db"?

ssquare's avatar

@staudenmeir

without port: "sqlsrv:Server=DESKTOP-H9OGJE5\MSSQLSERVER;Database=kpi_db" With port: "sqlsrv:Server=DESKTOP-H9OGJE5\MSSQLSERVER,1433;Database=kpi_db"

ssquare's avatar

@staudenmeir

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-H9OGJE5\MSSQLSERVER
DB_PORT=1433
DB_DATABASE=kpi_db
DB_USERNAME=root
DB_PASSWORD=123456

and

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-H9OGJE5\MSSQLSERVER
DB_PORT=1433
DB_DATABASE=kpi_db
DB_USERNAME=sa
DB_PASSWORD=

I have checked with both of this combination and with user root and sa both times gives same result for with port it also shows port and if no port provided it won't display port

staudenmeir's avatar

What I meant: Remove the port (1433), the whole line should just be DB_PORT=.

ssquare's avatar

Yeah, I am saying the same. Without port also shows same error. "sqlsrv:Server=DESKTOP-H9OGJE5\MSSQLSERVER;Database=kpi_db"

ssquare's avatar

@staudenmeir I have an update now. If I test with following code.

<?php
$serverName = "(local)";
$connectionInfo = array( "Database"=>"kpi_db","UID"=>"root", "PWD"=>"123456");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>`

It shows following error

Connection could not be established. Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'root'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'root'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'root'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'root'. ) )

But if I tried with

<?php
$serverName = "DESKTOP-H9OGJE5\MSSQLSERVER";
$connectionInfo = array( "Database"=>"kpi_db","UID"=>"root", "PWD"=>"123456");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>`

I used to got different error Connection could not be established. Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. [message] => [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )

Could you get some clue?

Inquisitive's avatar
Level 9

To resolve this problem, change the Server authentication from Windows Authentication mode to SQL Server.

To change the authentication mode to SQL Server and Windows, follow these steps:

  1. On the computer that is running Microsoft SQL Server, open SSMS.
  2. In the Server name box, type the name of the instance of SQL Server. For default, you can use dot(.) or (local)
  3. After connecting, in the Object Explorer window pane, right-click the SQL Instance and select Properties.
  4. Click Security under the select a page options.
  5. Change Server Authentication to SQL Server and Windows Authentication and click ok.
  6. Click ok to the prompt message about changes not taking effect until the instance is restarted.
  7. Right-click the SQL Instance in the Object Explorer and select Restart. Click Yes to restart the instance and if prompted to restart the SQL Server Agent.

After these changes have been applied and the SQL Instance has been restarted, attempt to verify the ODBC connection with the ‘sa’ account credentials.

Then try to connect through

<?php
$serverName = ".";
$connectionInfo = array( "Database"=>"kpi_db","UID"=>"sa", "PWD"=>"");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

If it successfully connected, remove port and fill other credentials.

Also, make sure you have copied extensions to ext folder and php.ini both in apache and php folder. As one is responsible for command and other is for the server. Let me know if any error arises.

3 likes
ssquare's avatar

Thank you actually I need to make change to SQL server authentication. That is the key what I am missing. Also, as you suggest I need to place drive on both ext folder.

rharrison1971's avatar

Also I was caught out with this error when using xamp with a virtual host. I changed the port from 80 to 8000 but forgot to change the vhost file to reflect the port change. Just thought I'd add this for any other poor soul.

jbatun21564065's avatar

For this problem, after any time of investigation with the same problem I have discovered that it is necessary that I have also installed the ODBC drivers of the Sql server, they are two components, necessary for the installation The SQL Server drivers for PHP The ODBC drivers for the database.

This is a old link wiht a explication of how to work drivers of SQL server of php https://docs.microsoft.com/en-us/sql/connect/php/microsoft-php-driver-for-sql-server?view=sql-server-2017

pSebstead's avatar

I dont see an ext folder inside my apache folder, I only have ext in my php folder. I was able to connect through xampp until I tried using the laravel framework, now its refusing my connection.

Next

Please or to participate in this conversation.