title: Can't connect to Mssql server running in docker container on Mac from CLI or pyodbc - Azure DS works?
body: <p>I am currently unable to connect to a MSSQL server I have running in a docker container on my mac laptop using any CLI tools or pyodbc. Connecting to, and interacting with the database with pyodbc is the goal. Strangely, using Azure Data Studio I can connect without issue. </p>
  
  <p>I followed the following two tutorials to install Sql server on my mac, and then restore an old backup of an existing server. </p>
  
  <p><a href="https://database.guide/how-to-install-sql-server-on-a-mac/" rel="nofollow noreferrer">https://database.guide/how-to-install-sql-server-on-a-mac/</a>
  <a href="https://database.guide/how-to-restore-a-sql-server-database-on-a-mac-using-azure-data-studio/" rel="nofollow noreferrer">https://database.guide/how-to-restore-a-sql-server-database-on-a-mac-using-azure-data-studio/</a></p>
  
  <p>Microsoft's suggested sqlcmd statement did not work for me</p>
  
  <pre><code>    sqlcmd -S &lt;ip_address&gt;,1433 -U SA -P '&lt;YourNewStrong!Passw0rd&gt;'
  </code></pre>
  
  <p>that was documented here: <a href="https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017&amp;pivots=cs1-bash" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017&amp;pivots=cs1-bash</a></p>
  
  <ul>
  <li><p>when I first installed docker, I did not increase the memory allocation to 4GB. I did so after my container was running and restarted the container and the mac itself. My understanding is that that memory should be available to that container now. </p></li>
  <li><p>I have tried mssql, sqlcmd, pyodbc with various connection parameters, but none of them are working for me. </p></li>
  <li><p>I CAN connect through Azure Data Studio with the following connection information: 
  Connection Type: Microsoft SQL Server
  Server: localhost,1401
  Authentication type: Sql Login 
  Username: sa
  password:  </p></li>
  </ul>
  
  <p>Based on my success interacting with the database through ADS, I've been assuming that there are errors with the connection parameters I'm passing to the CLI tools, but at this point I think I've tried just about every permutation I can think of. I've included some connection attempts and the errors they throw. </p>
  
  <p>I have read many other github and stack overflow tickets, it looks like the usual causes of this issue are people not running their container or not using a sufficiently complicated PW. That does not appear to apply in my circumstance. </p>
  
  <pre><code>$ sqlcmd -S 172.17.0.2,1433 -U SA -P &lt;TestPW123$&gt; 
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code>SqlState HYT00, Login timeout expired
  HResult 0x102, Level 11, State 0
  TCP Provider: Error code 0x102
  HResult 0x102, Level 11, State 0
  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 information see SQL Server Books Online.
  </code></pre>
  
  <hr>
  
  <pre><code>$ sqlcmd -S localhost,1433 -U SA -P &lt;TestPW123$&gt; 
  </code></pre>
  
  <p>RESULT:</p>
  
  <pre><code>sqlcmd(992,0x112ef45c0) malloc: can't allocate region
  *** mach_vm_map(size=18446744073709527040) failed (error code=3)
  </code></pre>
  
  <hr>
  
  <pre><code>$ mssql -s localhost -o 1433 -u sa -p &lt;TestPW123$&gt; 
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Connecting to localhost...
  Error: Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433
  </code></pre>