title: Connection string property has not been initialized Entity Framework Core
body: <p>Facing this exception message in my GenericRepository </p>
  
  <blockquote>
    <p>The ConnectionString property has not been initialized</p>
  </blockquote>
  
  <p>I have already configured my connection in <code>Startup.cs</code> like this:</p>
  
  <pre><code>services.AddDbContext&lt;DataContext&gt;(opt =&gt; opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  </code></pre>
  
  <p>I have another query where I am calling stored procedure and its fetching records. But when I am accessing DB from EF it's throwing this error. </p>
  
  <p>NOTE: I have written a UNIT Test for this piece of code and it works and fetch records from DB.</p>
  
  <p>Stack Trace</p>
  
  <blockquote>
    <p>at System.Data.SqlClient.SqlConnection.PermissionDemand()
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource<code>1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource</code>1 retry)
       at System.Data.SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.d__48.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.d__45.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<code>1.AsyncEnumerator.&lt;BufferlessMoveNext&gt;d__12.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.&lt;ExecuteAsync&gt;d__7</code>2.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable<code>1.AsyncEnumerator.&lt;MoveNext&gt;d__11.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator</code>2.d__7.MoveNext() in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Select.cs:line 106
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable<code>1.ConfiguredTaskAwaiter.GetResult()
       at System.Linq.AsyncEnumerable.AsyncIterator</code>1.d__10.MoveNext() in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor<code>1.EnumeratorExceptionInterceptor.&lt;MoveNext&gt;d__5.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable</code>1.ConfiguredTaskAwaiter.GetResult()
       at System.Linq.AsyncEnumerable.d__6<code>3.MoveNext() in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line 120
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter</code>1.GetResult()
       at Repositories.GenericRepository`1.d__9.MoveNext() in 
    Repositories\Implementations\GenericRepository.cs:line 122</p>
  </blockquote>