【发布时间】:2016-03-14 10:36:40
【问题描述】:
我在一个transaction scope 中编写了以下函数having two database context。我正在使用MySql 和EF 5.0
private static void SyncPremiumStores(JoyRydeWebPortalData.joyryde_WebPortalEntities contextWebPortal, JoyRydeMallStoreData.joyryde_MallStoreEntities contextMallStore)
{
using (TransactionScope scope = new TransactionScope())
{
foreach (var objWebPortalPremiumStore in contextWebPortal.tbl_premium_store.Where(x => x.INT_DATA_TRANS_STATUS == 0).ToList())
{
try
{
var objMallStore = contextMallStore.tbl_store.Where(x => x.LNG_STORE_ID == objWebPortalPremiumStore.LNG_STORE_ID).FirstOrDefault();
if (objMallStore != null)
{
JoyRydeMallStoreData.tbl_premium_store objMallPremiumStore = new JoyRydeMallStoreData.tbl_premium_store()
{
DAT_CREATED = objWebPortalPremiumStore.DAT_CREATED,
DAT_PREMIUM_FROM = objWebPortalPremiumStore.DAT_PREMIUM_FROM,
DAT_PREMIUM_TO = objWebPortalPremiumStore.DAT_PREMIUM_TO,
LNG_PRIMARY_STORE_ID = objMallStore.LNG_PRIMARY_STORE_ID,
LNG_STORE_ID = objMallStore.LNG_STORE_ID,
TXT_PACK_NAME = ""
};
contextMallStore.tbl_premium_store.Add(objMallPremiumStore);
objWebPortalPremiumStore.INT_DATA_TRANS_STATUS = 1;
}
contextMallStore.SaveChanges();
contextWebPortal.SaveChanges();
scope.Complete();
}
catch (Exception ex)
{
LogUtility.WriteErrorLog(ex);
}
}
}
}
在执行时,它会抛出错误
var objMallStore = contextMallStore.tbl_store.Where(x => x.LNG_STORE_ID == objWebPortalPremiumStore.LNG_STORE_ID).FirstOrDefault(); 带有内部异常消息的行
Multiple simultaneous connections or connections with different connection strings inside the same transaction are not currently supported.
我需要在单个事务中更新两个不同的数据库。 怎么办??
【问题讨论】:
标签: c# mysql entity-framework transactionscope