Unable to connect SQLEXPRESS with Laravel 5.6

前端 未结 1 1910
误落风尘
误落风尘 2021-01-07 04:45

I\'m trying to connect Laravel 5.6 to my SQLEXPRESS.

When I try to migrate tables from Laravel to SQL, I am getting this error:

SQLSTATE[08001

相关标签:
1条回答
  • 2021-01-07 05:20

    First, find port number of the default instance:

    • check the port number. If you have MS SQL Server Management Studio, execute: xp_readerrorlog 0, 1, N'Server is listening on' in master database

    • with command prompt (there will be a lot of rows, but you must analyze): netstat -ano

    Possible solutions:

    • stop SQL Server Browser service and test again, always with port number. You can connect to the default instance of SQL Server with TCP/IP if it is running on port 1433
    • set SQL Server not to use dynamic ports and set the port number of default instance.
    • change config/database in Laravel to find a way to skip port number. I don't have experience with Laravel, but I think that you can try with 'port' => env('DB_PORT', null),

    How to configure server to listen to specific port:

    • Open "Computer Management\Services\SQL Server Configuration Manager".
    • Expand "SQL Server Network Configuration\Protocols for [instance name]" and double click "TCP/IP". In the "TCP/IP Properties" dialog box, on the IP Addresses tab, go to IPAll. Leave "TCP Dynamci port" empty. Set "TCP Port" to desired port number (could be default 1433).
    • In the "SQL Server Services", double-click SQL Server Browser. In "Service" tab set "Start Mode" to "Manual".
    • In the "SQL Server Services", double-click SQL Server Browser. In "Log On" stop service.
    • In the "SQL Server Services", double-click SQL Server ([instance name]). In "Log On" restart service.
    • Set client connection string to "server\instance,port" format.

    Good starting points are: SQL Server Browser Service and Configure a Server to Listen on a Specific TCP Port

    I hope this can help you.

    0 讨论(0)
提交回复
热议问题