I was developing an application with Laravel 5.5 with a Mysql database. Everything was working normally, however, now the database has been modified to SQL Server.
When I run the test, it returns the error "Invalid handle returned."
- Searching, I saw that it could be the version of my php, so I changed the same, I was using 7.1 and now I'm in 7.0.23
- All drivers (including pdo_sqlsvr) are downloaded and set correctly (php.ini and ext folder)
- Microsoft ODBC installed
- All sql server firewall rules are configured and released
My .env file is set as follows:
APP_NAME=Incorptech
APP_ENV=local
APP_KEY=[key da aplicação está ok]
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=sqlsrv
DB_HOST=[host está ok]
DB_PORT=1433
DB_DATABASE=[nome do banco]
DB_USERNAME=[usuario do banco]
DB_PASSWORD=[senha do banco]
database.php
has the following settings:
'default' => env('DB_CONNECTION', 'sqlsrv'),
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'nomedobanco'),
'username' => env('DB_USERNAME', 'usuario'),
'password' => env('DB_PASSWORD', 'senha'),
'charset' => 'utf8',
'prefix' => '',
],
The function that I am performing the test and that this error is returning, is as follows:
public function testeDB() {
$select = DB::select('select * from conta');
return $select;
}
At the artisan command prompt, the following error appears:
PHP Fatal error: Invalid handle returned in ... vendor \ laravel \ framework \ src \ Illuminate \ Database \ Connectors \ Connector.php online 67
The function of line 67 of the error above (this function is the laravel itself), in the file \Connectors\Connector.php
is as follows:
protected function createPdoConnection($dsn, $username, $password,
$options) {
if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
return new PDOConnection($dsn, $username, $password, $options);
}
return new PDO($dsn, $username, $password, $options);
}
I started to develop in Laravel soon, is there anything else to be created for this connection to SQL Server to be successful?