简体   繁体   English

Mac:无法通过 Docker 连接到 SQL 服务器

[英]Mac: Cannot connect to SQL server through Docker

I have an application which uses LocalDB and runs fine on a Windows PC, however I am trying to run this through my mac.... I'm struggling with connecting the application to a mySQL server which sits on docker.我有一个使用 LocalDB 并在 Windows PC 上运行良好的应用程序,但是我试图通过我的 mac 运行它.... I have been following the other guides such as ( https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash ) related to this topic with no luck...我一直在关注其他指南,例如( https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash )与这个话题没有运气...

Here's what I've done so far, through terminal:到目前为止,这是我通过终端所做的:

  • sudo docker pull mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04须藤 docker 拉 mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04

  • sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<MyPassword123!>" sudo docker 运行 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<MyPassword123!>"
    -p 1433:1433 --name sql_container -p 1433:1433 --name sql_container
    -d mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04 -d mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04

  • Verified this is running by using sudo docker ps -a使用sudo docker ps -a验证这是在运行验证容器运行

  • Also verified by using Kitematic, container seems to be running well也通过使用 Kitematic 验证,容器似乎运行良好

  • MySQL looks well set-up in System Preferences MySQL 在系统偏好设置中看起来设置得很好

系统偏好设置的图像

  • I am able to connect to the container through Azure Data Studio using IP address as server name, as shown below我可以使用 IP 地址作为服务器名称,通过 Azure Data Studio 连接到容器,如下所示

Azure 数据工作室 在此处输入图像描述

  • Within the Application, this is is what the ConnectionStrings look like within the appsettings.json folder...在应用程序中,这就是连接字符串在 appsettings.json 文件夹中的样子... appSettings.json
  • However, when I run the application and try and hit the container, through a GET request OR on Swagger, I am met with the following reply;但是,当我运行应用程序并尝试通过 GET 请求或在 Swagger 上访问容器时,我收到以下回复; "error": "Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started." “错误”:“无法连接到 SQL 服务器浏览器。确保 SQL 服务器浏览器已启动。”
  • I have researched this and tried the solution of including the port number after the IP number as such Server=(19X.XXX.X.XX, 1433) but this also comes back with the error;我对此进行了研究并尝试了在 IP 编号之后包含端口号的解决方案,例如Server=(19X.XXX.X.XX, 1433)但这也返回了错误; "error": "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)" “错误”:“在建立与 SQL 服务器的连接时发生与网络相关或特定于实例的错误。未找到或无法访问服务器。验证实例名称是否正确以及 SQL 服务器配置为允许远程连接.(提供者:TCP 提供者,错误:25 - 连接字符串无效)”

I'm not sure where to go from here... any help to get this working would be greatly appreciated!我不确定从这里到 go 的位置......任何帮助来完成这项工作将不胜感激!

As trivial as it was, the correct syntax to make this work is Server=XXX.XXX.X.XX,1433尽管它很简单,但使这项工作的正确语法是 Server=XXX.XXX.X.XX,1433

DO NOT INCLUDE PARENTHESES AND NO SPACE BETWEEN IP AND PORT IP 和 PORT 之间不包括括号并且没有空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM