Hi I am trying to make my WebApi to work, but I have an error of database closed when I call the same method twice, the example below works fine:
public virtual async Task<IEnumerable<T>> Get<T>()
{
using (var dbCon = DbConnectionFactory.OpenDbConnection())
{
return await dbCon.SelectAsync<T>();
}
}
but the example below doesnt work I receive the error "connection is closed" (IT WORKS Perfectly if I don't use Async) *Using Async it doesnt work in the example bellow
protected virtual oid DbConnExec(Action<IDbConnection> dbConnFn)
{
using (var dbCon = DbConnectionFactory.OpenDbConnection())
{
dbConnFn(dbCon);
}
}
public virtual async Task<IEnumerable<T>> Get<T>()
{
return await DbConnExec(con => con.SelectAsync<T>());
}
THANKS!!
====
- Response Status
- Error Code
- InvalidOperationException
- Message
- Invalid operation. The connection is closed.
- Stack Trace
- [Employees:
26/01/2015 11:44:27 PM]:
[REQUEST: {}]
System.InvalidOperationException: Invalid operation. The connection is
closed.
at System.Data.SqlClient.SqlConnection.GetOpenTdsConnection()
at System.Data.SqlClient.SqlCommand.WaitForAsyncResults(IAsyncResult
asyncResult)
at
System.Data.SqlClient.SqlCommand.InternalEndExecuteReader(IAsyncResult
asyncResult, String endMethod)
at
System.Data.SqlClient.SqlCommand.EndExecuteReaderInternal(IAsyncResult
asyncResult)
at
System.Data.SqlClient.SqlCommand.EndExecuteReaderAsync(IAsyncResult
asyncResult)
at
System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult
iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean
requiresSynchronization)
--- End of stack trace from previous location where exception was thrown
---
at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
at
Next.Management.Repository.RepositoryBase.<Get>d__7`1.MoveNext()
--- End of stack trace from previous location where exception was thrown
---
at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
at Next.Management.Service.EmployeeService.<Get>d__6.MoveNext()