title: Can't connect to SQL 2008 database using .NET Core 2.0
body: <p><strong>UPDATE</strong></p>
  
  <p>I could never make this work with a "Windows Authentication" (domain) user. But with a "SQL Server Authentication" user everything is working like it's supposed to.</p>
  
  <p><strong>ORIGINAL QUESTION</strong></p>
  
  <p>My connectionString: <code>Server=ip;Database=dbname;User Id=xxx\user;Password=pass;</code></p>
  
  <p>The connection string is located in appsettings.json like this:</p>
  
  <pre><code>{
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "ConnectionStrings": {
      "ConnectionString": "Server=ip;Database=dbname;User Id=xxx\user;Password=pass;"
    }
  }
  </code></pre>
  
  <p>Then i pass it to a static class from the "Startup.cs" file, like this:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      // Add framework services.
      services.AddMvc();
  
      Orm.DatabaseConnection.ConnectionString = Configuration["ConnectionStrings:ConnectionString"];
  }
  </code></pre>
  
  <p>This is where I initiate the connection:</p>
  
  <pre><code>using System.Data.SqlClient;
  
  namespace MyProject.Orm
  {
      public static class DatabaseConnection
      {
          public static string ConnectionString { get; set; }
  
          public static SqlConnection ConnectionFactory()
          {
              return new SqlConnection(ConnectionString);
          }
      }
  }
  </code></pre>
  
  <p>And this is my controller:</p>
  
  <pre><code>public string Get()
  {
      using (var databaseConnection = Orm.DatabaseConnection.ConnectionFactory())
      {
          var sections = databaseConnection.Query("SELECT * FROM myTable").ToList();
          return sections.ToString();
      }
  }
  </code></pre>
  
  <p>Where this line:</p>
  
  <pre><code>var databaseConnection = Orm.DatabaseConnection.ConnectionFactory();
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>ServerVersion: "'databaseConnection.ServerVersion' threw an exception of type 'System.InvalidOperationException'"
  Message: "Invalid operation. The connection is closed."
  Source: "System.Data.SqlClient"
  StackTrace: "at 
  System.Data.SqlClient.SqlConnection.GetOpenTdsConnection()\n   
  at 
  System.Data.SqlClient.SqlConnection.get_ServerVersion()"
  </code></pre>
  
  <p>And i get this error on <code>new SqlConnection</code>: <code>"error CS0119: 'SqlConnection' is a type, which is not valid in the given context"</code>.</p>
  
  <p>But the program execution doesn't stop because of these errors.</p>
  
  <p>The application then hangs on the following line:</p>
  
  <pre><code>var sections = databaseConnection.Query("SELECT * FROM myTable").ToList();
  </code></pre>
  
  <p>I'm using Dapper as my ORM (not EntityFramework). In "myTable" sql table are only 17 rows and 5 columns so it should load fast.</p>
  
  <p>I tried all kinds of different connectionStrings but it always fails. If i try the same with .NET Framework 4.5, everything works fine. The problem is  .NET Core 2.0.</p>
  
  <p>Any idea about fixing it is welcome. Because i spent too many hours on this already.</p>