title: Cannot connect to SQL from DotNet Core via VPN
body: <p>I've tried solving this problem for days now, so I'm trying here to see if anyone have any more ideas to try.</p>
  
  <p>I can connect fine to my local SQL Express, but when trying to connect to SQL located at two different companies with separate VPNs, I can't from .NET Core / VS Code / dotnet.exe.</p>
  
  <p>I have this problem on a new laptop provided by my employer.</p>
  
  <p>What I've tried so far to solve this:</p>
  
  <ul>
  <li>Checked the <strong>ConnectionString</strong> a 1000 times</li>
  <li>Tried from <strong>my personal stationary computer</strong> with the same applications and connected to VPN, <strong>works fine</strong></li>
  <li>Connected from Microsoft SQL Server Management Studio, <strong>works fine</strong>, same SQL account used as in ConnectionString</li>
  <li>Checked server ports with PortQueryUI.exe: UDP port 1434 is <strong>LISTENING</strong>, TCP port 1433 (ms-sql-s service): <strong>LISTENING</strong></li>
  <li>Tried with IP in ConnectionString prefixed with "<strong>tcp:</strong>" and/or suffixed with "<strong>,1433</strong>"</li>
  <li>Downgraded .NET Core SDK to use <strong>2.1.1</strong> (same as stationary computer), down from <strong>2.1.16</strong>, same errors</li>
  <li>Opened outgoing and incomming TCP 1433 and UDP 1434 in Windows firewall</li>
  <li>Added VSCode and dotnet.exe to allowed applications in Windows firewall</li>
  <li>Both wireless network and VPN connection is set to "Private"</li>
  <li>Ran VSCode as Administrator (and not)</li>
  <li>Tried both User version and Computer version of the installation</li>
  <li>Verified that the ConnectionString in <code>appSettings.json</code> is actually used when running code (inspected while debugging)</li>
  </ul>
  
  <p>ConnectionString format:</p>
  
  <pre><code>"DefaultConnection": "Server=&lt;IPToServer&gt;;Database=&lt;DBName&gt;;User ID=&lt;UserName&gt;;Pwd=&lt;Password&gt;"
  </code></pre>
  
  <p>Neither is a named instance, one is SQL Express, one is SQL Server.</p>
  
  <p>Error without <strong>tcp:</strong>:</p>
  
  <pre><code>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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
  
  System.ComponentModel.Win32Exception (1326): The user name or password is incorrect
  </code></pre>
  
  <p>But the Username and Password is not incorrect. I get that message from MSSMS when switching to Names Pipes too, but when changing to TCP, I can connect (from MSSMS).</p>
  
  <p>Error with <strong>tcp:</strong>:</p>
  
  <pre><code>An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call.
  
  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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
  </code></pre>
  
  <p>Anyone have any ideas what to try? Since it's working from my other computer I'm pretty sure it's something on my laptop that's causing it.</p>