本文介绍了如何从Linux Docker容器连接到本地SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows计算机上运行的linux Docker容器连接到我的SQL Server本地实例。在Windows下运行时,我可以使用 Data Source = localhost 成功连接。我已经 localhost ,因此这也是我尝试过并失败的内容:

I am trying to connect to my local instance of SQL Server using a linux Docker container running on my Windows machine. I can connect successfully using Data Source=localhost when running under Windows. I've discovered that localhost is not supported in a connection string on linux, so here is what I've also tried and failed with:


  • Data Source = localhost

  • Data Source = localhost,1433

  • 数据源= 127.0.0.1

  • 数据源= 127.0.0.1,1433

  • 数据源= 127.0.0.11

  • Data Source = 127.0.0.11,1433

  • Data Source = 172.23.0.1 -我的本地IP地址

  • 数据源= 172.23.0.1,1433

  • Data Source=localhost
  • Data Source=localhost,1433
  • Data Source=127.0.0.1
  • Data Source=127.0.0.1,1433
  • Data Source=127.0.0.11
  • Data Source=127.0.0.11,1433
  • Data Source=172.23.0.1 - My local IP Address
  • Data Source=172.23.0.1,1433

我的本​​地SQL Server实例不允许远程连接。我怀疑这就是为什么我无法连接。我是否需要允许远程连接才能使其正常工作?

My local SQL Server instance does not allow remote connections. I suspect this is why I cannot connect. Do I need to allow remote connections to get this to work? Can I get this working without doing so?

此外,如果我必须提供IP地址,是否可以通过编程的方式确定该地址是什么? / p>

Also, if I have to provide an IP address, is there a way to work out what that address should be programmatically?

推荐答案

您可以尝试使用 Data Source = host.docker.internal

这篇关于如何从Linux Docker容器连接到本地SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:46