Hi,
So as first step i am trying to create Database transaction as shown in the below code
try {
using (var dbContext = new DatabaseContext(context))
{
using (var dbTransaction = await dbContext.BeginTransactionAsync())
{
var sqlQuery = new SqlQuery
{
QueryString = sql
};
//setting parameters here
await dbContext.ExecuteNonQueryAsync(sqlQuery);
dbTransaction.Commit();
}
}
}
catch(Exception ex)
{
throw ex;
}
the above code throws error "This API is not supported in non-persisted connection mode.".
Now i have changed the code as below to allow persisted connection.
try {
using (var dbContext = new DatabaseContext(context, DatabaseConnectionMode.IsPersisted))
{
using (var dbTransaction = await dbContext.BeginTransactionAsync())
{
var sqlQuery = new SqlQuery
{
QueryString = sql
};
//parameters
await dbContext.ExecuteNonQueryAsync(sqlQuery);
dbTransaction.Commit();
}
}
}
catch(Exception ex)
{
throw ex;
}
with the above code it throws error "BeginExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."