B
Born2Achieve
Guest
Hello,
I am using net core 2.2 and i would need to use the transaction scope. on my business layer i am using transaction scope as follows
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = new TimeSpan(0, 10, 0);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
// Method 1 which has DB connnection am opening and coling the connection properly
// Method 2 which has DB connnection am opening and coling the connection properly
// Method 3 which has DB connnection am opening and coling the connection properly
scope.Complete();
}
DAL layer
public class EmpDB : DbContext
{
public EmpDB()
{
}
public EmpDB(DbContextOptions<EmpDB> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(//ConnectionString);
}
}
public int GetEmpId(string EmpEmail)
{
using (EmpDB empDB = new EmpDB())
{
using (var dbCommand = empDB.Database.GetDbConnection().CreateCommand())
{
// proc call with parameters
if (dbCommand.Connection.State != ConnectionState.Open)
{
dbCommand.Connection.Open();
}
int EmpId = (int)dbCommand.ExecuteScalar();
dbCommand.Connection.Close();
return EmpId
}
}
}
}
am not sure what mistake am doing??? please help me to solve this error. i tried to google through and people are saying .net core 2.2 supports transaction scope. please suggest to solve the issue
loving dotnet
Continue reading...
I am using net core 2.2 and i would need to use the transaction scope. on my business layer i am using transaction scope as follows
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = new TimeSpan(0, 10, 0);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
// Method 1 which has DB connnection am opening and coling the connection properly
// Method 2 which has DB connnection am opening and coling the connection properly
// Method 3 which has DB connnection am opening and coling the connection properly
scope.Complete();
}
DAL layer
public class EmpDB : DbContext
{
public EmpDB()
{
}
public EmpDB(DbContextOptions<EmpDB> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(//ConnectionString);
}
}
public int GetEmpId(string EmpEmail)
{
using (EmpDB empDB = new EmpDB())
{
using (var dbCommand = empDB.Database.GetDbConnection().CreateCommand())
{
// proc call with parameters
if (dbCommand.Connection.State != ConnectionState.Open)
{
dbCommand.Connection.Open();
}
int EmpId = (int)dbCommand.ExecuteScalar();
dbCommand.Connection.Close();
return EmpId
}
}
}
}
am not sure what mistake am doing??? please help me to solve this error. i tried to google through and people are saying .net core 2.2 supports transaction scope. please suggest to solve the issue
loving dotnet
Continue reading...