我正在开发一个需要连接到MS SQL数据库的项目,我有一个托管在Microsoft Azure中的云数据库,我可以使用SQL Server Management Studio访问它,但是在我的Laravel项目中试图查询我得到。我已经在Azure防火墙中允许了我的IP地址。
PDOException in Connector.php line 47: SQLSTATE[08001]: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
这是我的配置
'azure' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'ybefh1h7kh.database.windows.net,1433'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'password'),
'prefix' => '',
],
我的查询
$users = DB::connection('azure')->select("SELECT * FROM Users");
var_dump($users);exit;
答案 0 :(得分:0)
使用此
'azure' => [
'driver' => 'sqlsrv',
'host' => 'ybefh1h7kh.database.windows.net,1433',
'database' => 'test',
'username' => 'myuser',
'password' => 'password',
'prefix' => '',
],