1、微软自带事务和锁
private static object _lock = new object();
try{
using (TransactionScope scope = new TransactionScope())
{
lock (_lock)
{
}
scope.Complete();
}
}
catch (Exception ex)
{
TJson.setSucc(jOutput, false, "添加失败");
TTracer.WriteLog(ex.ToString());
}
2、 StringBuilder sWhere = new StringBuilder();
IList<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
TransactionOptions transactionOption = new TransactionOptions();
transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;//设置事务的隔离级别
transactionOption.Timeout = new TimeSpan(0, 0, 60); //设置事务超时时间60秒
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,transactionOption))
{
foreach (var item in queryWhere)
{
if (item.Value.ToString() != "")
{
sWhere.Append(" and " + item.Key + " like '%" + item.Value + "%'");
}
}
string mySQL = string.Format(@"(select * from EHECD_StoreInformation where 1=1 {0})", sWhere.ToMSSQLValue());
string etpageSQL = EtPageSQL.GetMSSsqlPagingSQL(pageNumber, pageSize, mySQL);
list = dbhelper.GetDictionaryList(etpageSQL);
scope.Complete();
}
return list;