title: ASP.NET: Why can I execute query once only?
body: <p>I have an ASP.NET service. Inside it I use the access to SQL Server, i.e. add the DbConnection etc</p>
  <pre><code>  services.AddScoped&lt;IDbConnection, SqlConnection&gt;(_ =&gt; new SqlConnection(sqlcon));
    services.AddScoped&lt;ICRepository, CRepository&gt;();
  </code></pre>
  <p>This DbConnection used in the classes which queried a db.</p>
  <p>BUT I can execute the query 1st time and it returns the correct items.
  If I execute it the 2nd time I receive:
  &quot;message&quot;: &quot;The ConnectionString property has not been initialized.&quot;</p>
  <p>and really the dbconnection object is empty and not initialized
  How to fix it?
  That is minimized piece of code</p>
  <pre><code> public class CRepository : ICRepository
      {
          private readonly IDbConnection _db;
  
          public CRepository(IDbConnection db)
          {
              _db = db;
          }
  //....
          public List&lt;MyAction&gt; GetMyActions()
          {
              var sql = $@&quot;
                  SELECT id,name, description from actions;&quot;;
  
              var result = _db.Query&lt;MyAction&gt;(sql).ToList();
              return result;
          }
  ...
  }
  </code></pre>
  <p>ANd the first time the _db is initialized but the 2nd one - no.</p>