/// <summary> /// 同步地區的處理 /// Base_Area表從Oracle同步到MySQL數據庫 /// </summary> /// <returns></returns> public ActionResult SyncAreaFromOracleToMySql() { BaseResult baseResult = new BaseResult(); string currentId = string.Empty; try { BaseAreaManager areaOracleManager = new BaseAreaManager(UserCenterDbHelper, OperateContext.Current.UserInfo); //MySQl庫 string mySQLConn = "server=192.168.3.12;uid=root;password=123456;database=sapp2;pooling=true;character set=utf8;Min Pool Size=5;Max Pool Size=50"; IDbHelper mySQLDbHelper = DbHelperFactory.GetHelper(CurrentDbType.MySql, mySQLConn); BaseAreaManager areaMySQLManager = new BaseAreaManager(mySQLDbHelper, OperateContext.Current.UserInfo); using (IDataReader dr = areaOracleManager.ExecuteReader(0, BaseAreaEntity.FieldCode)) { while (dr.Read()) { BaseAreaEntity entity = BaseEntity.Create<BaseAreaEntity>(dr, false); currentId = entity.Id; int result = areaMySQLManager.Update(entity); if (result == 0) { areaMySQLManager.Add(entity, false, false); } } } baseResult.Status = true; baseResult.StatusMessage = "地區數據同步到MySql完成。"; } catch (Exception ex) { baseResult.Status = false; baseResult.StatusMessage = "地區數據Id=" + currentId + "同步到MySql出現異常:" + ex.Message; } return Json(baseResult, JsonRequestBehavior.AllowGet); }
直接上代碼了,上面實現的功能是從Oracle庫將Base_Area表導入到MySQL庫中Base_Area表的功能實現,一樣能夠導入到其它庫中,充分利用了底層的功能,解決不一樣數據庫導入導出的問題。數據庫