Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free



When executing the API request to an ASP.Net application, the feedback comes in the API client:

Could not get any response

This seems to be like an error connecting to http://localhost:51081/api/Projects. The response status was 0.

Check out the W3C XMLHttpRequest Level 2 spec for more details about when this happens.


Error in the test client Postman



The error is caused when the ASP.Net application tries to access the database

// GET-all: api/Projects *List all Records


public IEnumerable<Project> Gettbl_Projects()


  return _context.tbl_Projects;





In C # with applications that access SQL Client Server, for values that can become NULL, you must define the local variables Nullable.


Correction in C #

This means that you have to end the variables DateTime, Integer, and Double with a question mark in the local data variables

Like here:

public DateTime DtList { get; set; }

public DateTime? DtScan { get; set; }


String variables in C # are automatically nullable and therefore do not need any correction.



Error display in detail:

There is already an open DataReader associated with this Command which must be closed first.



"System.Data.SqlClient"    string




Stack Trace on Connection

The stack trace incorrectly indicates an error with the SQL Connection.

StackTrace of the error

"   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)\r\n   at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)\r\n   at System.Data.SqlClient.SqlCommand.ValidateCommand(Boolean async, String method)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Common.DbCommand.ExecuteReader()\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)\r\n   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()\r\n   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)\r\n   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)\r\n   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n   at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()"          string


ASP.Net: A database operation failed while processing the request.
API error: Could not get any response
ASP Error: System.InvalidOperationException, An exception occurred while reading a database value
ASP EF Error: Unable to create object of type DbContext
» Error: No DbContext was found in assembly
» Errors: The entity type xxx requires a primary key to be defined.


Contact for Jobs, Project Requests: