title: TCP Provider connection refused - Laravel 6 and SQL Server (Microsoft) and Laragon
body: <p>I'm currently on a fresh install of Laravel 6 and trying to connect it to my Microsoft SQL Server, and I am serving it locally using Laragon.</p>
  
  <p>I have downloaded the ODBC driver for SQL Server.</p>
  
  <p>My database.php file contains:</p>
  
  <pre><code>'default' =&gt; env('DB_CONNECTION', 'sqlsrv'),
  
  ...
  
  'sqlsrv' =&gt; [
          'driver' =&gt; 'sqlsrv',
          'url' =&gt; env('DATABASE_URL'),
          'odbc' =&gt; true, // I added this line
          'odbc_datasource_name' =&gt; '{SQL Server}', // I added this line
          'host' =&gt; env('DB_HOST', 'localhost'),
          'port' =&gt; env('DB_PORT', '1433'),
          'database' =&gt; env('DB_DATABASE', 'forge'),
          'username' =&gt; env('DB_USERNAME', 'forge'),
          'password' =&gt; env('DB_PASSWORD', ''),
          'charset' =&gt; 'utf8',
          'prefix' =&gt; '',
          'prefix_indexes' =&gt; true,
   ],
  </code></pre>
  
  <p>And my .env contains the valid login credentials. To test that I can connect to the DB, I did a check in welcome.blade.php:</p>
  
  <pre><code>@php
      if (DB::connection()-&gt;getDatabaseName())
      {
          echo "connected successfully to database ".DB::connection()-&gt;getDatabaseName();
  
      }
  @endphp
  </code></pre>
  
  <p>Which echos onto my page as:</p>
  
  <blockquote>
    <p>connected successfully to database testDatabase</p>
  </blockquote>
  
  <p>I have gone into Tinker to see if I can get a Collection of all Employees from my model, i.e. Carer.php:</p>
  
  <pre><code>
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Carer extends Model
  {
      protected $table = "dbo.carer";
  
      protected $primaryKey = 'CarerID';
  }
  
      ...
  </code></pre>
  
  <blockquote>
    <p>$carer = App\Carer::all();</p>
  </blockquote>
  
  <p>Which returns:</p>
  
  <blockquote>
    <p>Illuminate/Database/QueryException with message 'could not find driver (SQL: select * from [dbo].[carer])'</p>
  </blockquote>
  
  <p>Does this mean my check for connecting to the database is faulty if I cannot find a driver when attempting to retrieve model data? Do I have to do something specific in Laragon to get it to work for SQL Server?</p>
  
  <p>Thank you.</p>
  
  <p>UPDATE: Following the instructions from <a href="https://forum.laragon.org/topic/102/problem-with-connection-between-sqlsrv_connect-with-php-script/5" rel="nofollow noreferrer">here</a> and <a href="https://codingofcents.com/sql/connect-php-to-microsoft-sql-server/" rel="nofollow noreferrer">here</a>, I have managed to add the PDO drivers to my php.ini file and get it running with Laragon. When I print out <code>phpinfo()</code> I can now see the sql servers.</p>
  
  <p>The error I am now getting is:</p>
  
  <blockquote>
    <p>Illuminate/Database/QueryException with message 'SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
     (SQL: select top 1 * from [dbo].[carer])'</p>
  </blockquote>