I have encounter this error while executing my source code. But it seems not much information I could get on the internet. Thus, I am hoping may get some clue from the professionals here.
Source Code
public List<string> GetData (List<long> Id)
{
List<string> data;
string sql = "select * from tblSample with(nolock) where SampleId in @sampleId";
Dapper.DynamicParameters param = new Dapper.DynamicParameters();
param.Add("@sampleId", Id);
try
{
data = this.queryrunner.QueryList(sql, param);
}
catch (Exception ex)
{
logger.Error(ex.Message, ex);
}
return data;
}
QueryRunner class method
private void OpenConnection()
{
if (this.conn.State != ConnectionState.Open)
{
this.conn.Open();
}
}
public List<t> QueryList(String sql, DynamicParameters param)
{
List<t> t;
try
{
OpenConnection();
t = this.conn.Query<t>(sql, param).ToList();
}
catch (System.Data.SqlClient.SqlException ex)
{
logger.Debug(ex.Message, ex);
LogSqlErrorException(this.conn.Database, sql, param);
throw;
}
finally
{
CloseConnection();
}
return t;
}
Here is part of the error log:-
System.InvalidOperationException: The current TransactionScope is already complete.
at System.Transactions.Transaction.get_Current()
at System.Data.ProviderBase.DbConnectionPool.GetFromTransactedPool(Transaction& transaction)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)
1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
at System.Data.SqlClient.SqlConnection.Open()
this.queryrunner.QueryList(sql, param);
>OpenConnection();
>this.conn.Open();
– JackyLoo