title: Laravel SQL Server connection in Custom Artisan Command
body: <p>I use several databases including a SQL Server database</p>
  <p><code>DB::connection('sqlsrv')-&gt;from('my_table')-&gt;get();</code></p>
  <p>In my model, if I use the classical method from a controller it works. But if I call this same method from a custom command, I get an error message that the drivers are not found.</p>
  <p><code>php artisan  test:example</code></p>
  <p>When executing the query, I got the following error message</p>
  <blockquote>
  <p>could not find driver (SQL:</p>
  </blockquote>
  <p>I also noticed that from my custom command, the database connection specified in the template was not taken into account.</p>
  <p><code>protected $connection = 'sqlsrv';</code></p>
  <p>The problem appeared since the migration from version 8 to version 9.</p>
  <p>On the same server, I have another site running with the same drivers and also using custom commands. He too was migrated from version 8 to version 9 and everything works perfectly.
  Locally it works very well.</p>
  <p>The behavior is really strange, thanks in advance for your help.</p>
  <p>I tried clearing the Laravel cache but still having the same problem.</p>
  <p>My database configuration (.env)</p>
  <pre><code>DB_CONNECTION_MSSQL=sqlsrv
  DB_HOST_MSSQL=192.1.1.10
  DB_PORT_MSSQL=1433
  DB_DATABASE_MSSQL=dbV3
  DB_USERNAME_MSSQL=web
  DB_PASSWORD_MSSQL=secret
  </code></pre>
  <p>In the config/database.php file</p>
  <pre><code>'sqlsrv' =&gt; [
              'driver' =&gt; 'sqlsrv',
              /*'url' =&gt; env('DATABASE_URL'),*/
              'host'     =&gt; env('DB_HOST_MSSQL', 'localhost'),
              'port'     =&gt; env('DB_PORT_MSSQL', '1433'),
              'database' =&gt; env('DB_DATABASE_MSSQL', 'forge'),
              'username' =&gt; env('DB_USERNAME_MSSQL', 'forge'),
              'password' =&gt; env('DB_PASSWORD_MSSQL', ''),
              /*'charset' =&gt; 'utf8',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,*/
          ],
  </code></pre>
  <p>In the model</p>
  <pre><code>protected $connection = 'sqlsrv';
  </code></pre>
  <p>Same problem with both ways</p>
  <pre><code>DB::connection('sqlsrv')-&gt;from('my_table')-&gt;get();
  </code></pre>
  <p>Or</p>
  <pre><code>$query = static::all();
  </code></pre>