【问题标题】:Connect host machine's SQL Server 2017 from homestead vagrant从 homestead vagrant 连接主机的 SQL Server 2017
【发布时间】:2018-09-17 01:25:30
【问题描述】:

我正在尝试从 Laravel vagrant homestead 连接我的本地/主机 SQL Server。我整天都在谷歌搜索,试图连接主机的数据库,安装不同的 PHP 包,但到目前为止还没有运气。我想此时我会删除 PHP 并尝试使用 sqlcmd 在宅基地内建立连接。

所以,我在宅基地安装了sqlcmd,并尝试执行以下命令连接到主机的数据库。

sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"

但是,我收到以下错误:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection due to prelogin failure.

但是,如果我在主机上使用sqlcmd 并执行以下命令,我就可以访问数据库。

sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"

在我的 Homestead.yaml 中,我设置了端口转发:

ports:
    - send: 1433
      to: 1433

【问题讨论】:

    标签: sql-server laravel vagrant homestead


    【解决方案1】:

    你说这行不通:

    sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
    

    但确实如此:

    sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
    

    在前者中,您使用的是 IP,但没有实例名称。

    试试:

    sqlcmd -S 10.0.2.2\MSSQL2017 -U sa -P 'password' -Q "sp_databases"
    

    还有: 在 SQL 网络配置中确保 TCP/IP is enabled

    验证 SQL Server Browser 是否正在运行。

    在 SQL Server 属性中允许远程连接。

    将 SQL 网络配置锁定到所有适配器上的端口 1433,并禁用动态端口(然后重新启动服务)。

    【讨论】:

    • 前者在vagrant ssh内部执行,第二个在宿主机上执行。我还确保启用了 TCP/IP Protocol for MSSQL2017 TCP/IP 并重新启动了 SQL Server (MSSQL2017)。它显示以下错误:
    • vagrant@homestead:~$ sqlcmd -S 10.0.2.2\MSSQL2017 -U sa -P 'password' -Q 'sp_databases' Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2AF9. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more informati vagrant@homestead:~$
    • 如果打开 services.msc,SQL Browser 服务是否正在运行?
    • 我找不到SQL Browser ServiceSQL Server Browser 正在运行
    • 有趣,您的主机上安装了防火墙吗?你能暂时放下来测试吗?你能ping/tracert那个IP吗?你能telnet到1433端口吗?
    猜你喜欢
    • 2015-03-24
    • 1970-01-01
    • 2017-05-02
    • 2014-11-26
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2013-11-24
    相关资源
    最近更新 更多